[webkit-dev] JSC binding code question

Kinuko Yasuda kinuko at chromium.org
Tue Sep 28 22:48:41 PDT 2010


Hi Webkit folks,

I'm writing a JSC binding code (custom binding code for now) for a
method that can take JSON-format parameters, and I want to know what
would be the right/recommended way.
I mean, I want to write a binding code that can executes javascript code like:

   directoryEntry.getFile("lockfile.txt", {create: true, exclusive: true});

Where the getFile() method is defined as:

   interface DirectoryEntry : Entry {
     void getFile(in DOMString path, in Flags flags, /* ... */);
   };
   interface Flags {
     attribute boolean create;
     attribute boolean exclusive;
   };

(They are from the File API: Directories and System's draft [1])

And what I have written for this is like following:

if (!exec->argument(1).isNull() && !exec->argument(1).isUndefined() &&
exec->argument(1).isObject() &&
!exec->argument(1).inherits(&JSFlags::s_info)) {
        JSObject* object = exec->argument(1).getObject();
        flags = Flags::create();
        JSValue jsCreate = object->get(exec, Identifier(exec, "create"));
        flags->setCreate(jsCreate.toBoolean(exec));
        JSValue jsExclusive = object->get(exec, Identifier(exec, "exclusive"));
        flags->setExclusive(jsExclusive.toBoolean(exec));
}

Basically the code calls JSObject::get() to get values for the given
property names.
This looked straightforward, but I was told that the get(exec)
re-enters Javascript and could do any arbitrary thing.
This means that during the get() even the parameter object or the
calling object (imp) may get deallocated.

So here I have two questions:

1) How can I write a safe binding code that reads JSON-format
parameters?  Is there some recommended way or any good idea?

2) I saw several other code doing the same/similar thing as I do
(calling JSObject::get()) to get arbitrary parameter values.
Are they safe?  Is there a guarantee that the code executed during
get() doesn't deallocate some objects?

Any help/suggestions/comments would be highly appreciated.
Thanks!
Kinuko


[1] http://dev.w3.org/2009/dap/file-system/file-dir-sys.html
[2] http://trac.webkit.org/browser/trunk/WebCore/bindings/js/JSDirectoryEntryCustom.cpp


More information about the webkit-dev mailing list