code-google-com / pyv8

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

Return undefined instead of null if python mapping type returns None #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I patched pyv8 to return v8 undefined instead of null in this case:

import PyV8

class Global():
    def __init__(self):
        self.g = self

    def write(self, val):
        print val

    def __getitem__(self, val):
        pass

context = PyV8.JSContext(Global())
with context as ctx:
    ctx.eval("""x = g.z; write(typeof x === "undefined")""")

The relevant code is in Wrapper.cpp, CPythonObject::NamedGetter

if (::PyMapping_Check(obj.ptr()) && ::PyMapping_HasKeyString(obj.ptr(), *name)) 
{    
            py::object result(py::handle<>(::PyMapping_GetItemString(obj.ptr(), *name)));
            if (result.ptr() == Py_None) {
                // return undefined     
                return v8::Handle<v8::Value>();
            }

            return Wrap(result);

        }

Original issue reported on code.google.com by ATM1...@gmail.com on 5 Apr 2011 at 7:21

GoogleCodeExporter commented 9 years ago

Original comment by flier...@gmail.com on 6 Apr 2011 at 1:54

GoogleCodeExporter commented 9 years ago
Thanks for your patch, please verify it with pyv8 SVN code after r359

Original comment by flier...@gmail.com on 6 Apr 2011 at 3:54