RoamUniverse / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

Add support for using mappings from JS #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If this is the following scope for the Javascript:

class Globals(PyV8.JSClass)
    d = {'a': {'b': 'c'}, 'd': ['e', 'f']}

then any attempt to access d.a or d.d will return undefined, which is
slightly unexpected (since JS treats d['a'] and d.a the same), and makes it
awkward to pass JSON data between Python and JS. Attaching a patch which
makes Named[GS]etter check if the object supports the mapping protocol, and
if so uses that instead.

Original issue reported on code.google.com by sciyoshi on 1 Jan 2010 at 8:44

Attachments:

GoogleCodeExporter commented 9 years ago
On second thought, the check for mapping should only be done if the attribute 
check
fails (rather than the other way around). This breaks some things when using the
BeautifulSoup DOM and env.js.

Original comment by sciyoshi on 1 Jan 2010 at 8:57

GoogleCodeExporter commented 9 years ago
I have added supports to use the python mapping protocol from Javascript side, 
please 
check out the source code from SVN after r189 to verify it.

As you know, the automatic mapping may introduce some compatibility issues, 
that's 
why I'm not implement it in previous version. To minimize the side effect, I 
limit the 
mapping only for the situation that the object follow python mapping protocol 
and 
doesn't have same named attribute. 

Thanks for your patch

Original comment by flier...@gmail.com on 2 Jan 2010 at 4:58