Giter VIP home page Giter VIP logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
[deleted comment]

from pyv8.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
I'm not sure what's your real problems, could you give me some example or unit 
test code?

In fact, _PyV8.JSArray support the python Sequence Protocol. It means, you 
could 
use its predefined methods such as __iter__, __len__ or __getitem__ etc. 

>>> list(ctxt.eval("new Array(1, 2, 3)"))
[1, 2, 3]                                
>>>                                      

On the other hand, javascript doesn't have build-in dictionary, even you could 
create object with JSON syntax, such as

>>> r = ctxt.eval("var r = {'a' : 1, 'b' : 2}; r ")
>>> r
<_PyV8.JSObject object at 0x00AE9170>
>>> dir(r)
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__float__', '__ge
tattr__', '__getattribute__', '__hash__', '__init__', '__int__', '__js__', '__me
mbers__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__red
uce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'a', 'b']
>>> r.a
1
>>> r.b
2

Original comment by [email protected] on 5 May 2009 at 4:02

from pyv8.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
[deleted comment]

from pyv8.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
hi flier,

thanks for pointing this out. it wasn't clear for that i can use the builtin 
__members__ to get all attributes to 
iterate over.

i've written a small function that converts a cx.eval()-result into a python 
dict. maybe someone needs this 
too.

cheers marc

Original comment by [email protected] on 5 May 2009 at 11:04

Attachments:

from pyv8.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 24, 2024
Thanks, I have merged your contribution in pyv8.py

http://code.google.com/p/pyv8/source/detail?r=123

on the other hand, I add some code to simulate a dict in JSObject class


    def testDict(self):
        import UserDict

        with JSContext() as ctxt:
            obj = ctxt.eval("var r = { 'a' : 1, 'b' : 2 }; r")

            self.assertEqual(1, obj.a)
            self.assertEqual(2, obj.b)

            self.assertEqual({ 'a' : 1, 'b' : 2 }, dict(obj))            

            self.assertEqual({ 'a': 1,
                               'b': [1, 2, 3],
                               'c': { 'str' : 'goofy',
                                      'float' : 1.234,
                                      'obj' : { 'name': 'john doe' }},                                      
                               'd': True,
                               'e': None },
                             convert(ctxt.eval("""var x =
                             { a: 1,
                               b: [1, 2, 3],
                               c: { str: 'goofy',
                                    float: 1.234,
                                    obj: { name: 'john doe' }},
                               d: true,
                               e: null }; x""")))

Original comment by [email protected] on 6 May 2009 at 3:45

  • Changed state: Fixed

from pyv8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.