[webkit-dev] GlobalScript API.
Patrick Mueller
pmuellr at muellerware.org
Tue Sep 1 05:25:03 PDT 2009
Dmitry Titov wrote:
> I'd appreciate much your advice on the whole API and on the way to bring it
> into WebKit.
I'm very interested in this, perhaps mainly as the first method
available in the browser/JavaScript space to be able to create new contexts.
>
> Here is an actual API:
> ---------------------------
> Page-level API
>
> var globalScript = new webkitGlobalScript(name, url, loadHandler,
> errorHandler);
I've mentioned before that this API turns out to be very similiar to the
serverJS notion of a "module".
https://wiki.mozilla.org/ServerJS/Modules/SecurableModules
Differences are the name: require -> webkitGlobalScript; semantics about
sharing across pages (not relevant to the serverJS work); the "exports"
variable in the module which provides the reference to the globalScript
return value the client sees; and that this is async vs. serverJS's sync
model.
Of most interest is the notion of the "exports" variable. Instead of
exposing the "global" scope of the global script itself as the return
value, you actually have to assign something to the exports variable
from within the global script for it to be available in the caller. The
nice thing about this is that it provides a nice way to create private
references within your global script.
It would probably be useful for folks to at least look at some of the
work going on in the serverJS world - actually, just remembered they
have changed their name to CommonJS. The narwhal work probably provides
a good concrete example of what they're doing (it's been a few months
since I looked at it in depth).
http://github.com/tlrobinson/narwhal/tree/master
I'm not a big fan of stringing fairly arbitrary parameters together as
the handlers seem to be in the webkitGlobalScript() function, especially
since it's pretty simple to send extendable objects instead. Would
prefer to see something like:
new webkitGlobalScript("foo", "foo.js", {
loadHandler: function(something) {},
errorHandler: function(something) {}
});
> API exposed to Global Script (on its global scope object)
> - Timers
> - XHR
> - Navigator
> - localStorage
> - Database
> - Workers
Previously mentioned was a way to load an additional script from within
the global script. Does the Workers API to do that handle this? That's
a sync API, right? Is that what we want?
--
Patrick Mueller - http://muellerware.org
More information about the webkit-dev
mailing list