W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2014

Re: Associating new objects with globals: how to best do it?

From: Allen Wirfs-Brock <allen@wirfs-brock.com>
Date: Tue, 25 Feb 2014 16:14:10 -0800
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>, Bobby Holley <bholley@mozilla.com>
Message-Id: <7AFC78AF-3E9D-4024-BE46-3D8C4985A387@wirfs-brock.com>
To: Boris Zbarsky <bzbarsky@MIT.EDU>

On Feb 25, 2014, at 11:57 AM, Boris Zbarsky wrote:

> On 2/25/14 1:48 PM, Allen Wirfs-Brock wrote:
>> 
> 
>  If value is null, undefined or not supplied return the result of the
>  abstract operation ObjectCreate with the intrinsic object
>  %ObjectPrototype% as its argument.

Note that the %foo% notation means the "foo" intrinsic (built-in object) associated with the Realm of the currently active function.

> ...
>> Everything that happens within an ECMAscript program happens in the context of executing some function (or a global script that is treated as if it was a function body)
> 
> While true at the moment of pure ES, this property does not hold for "ES + DOM" and may stop holding for ES itself in the future.  The API pattern that breaks down this property is an API that asynchronously performs some work that creates an object and then invokes some callback (or resolves some Promise) and hands it that object.  Such APIs need to use standard prototypes from some Realm when doing the async object creation.  Presumably the consistent thing to do here would be to use the [[Realm]] of the API entry point that kicked off the async operation.

Really? The callback function that will ultimately be invoked has a Realm association either because it is a "built-in" from some Realm or because it was a dynamically created closure which was created from within some other function and was assigned the same Realm as its creator.

Take a look at section 8.3 (Tasks and Task Queues) in the latest ES6 draft. (I can't give you a direct link because Jason's HTML version seems to be broken at the moment).  This is where the ES 6 spec. handles async operations including Promise resolutions. Once it gets to the point of actually calling a function itjust uses the Realm of that function.  The only funny part is what happens if a async action needs to do some work (like allocate an object, for example an exception) prior to actually invoking the function.  To account for that possibility we capture a Realm when an async task request is queue.  This would normally be the Realm of the built-in (for example a Promise method) that invoked the abstract operation to enqueue a task.  

Alleb
Received on Wednesday, 26 February 2014 00:14:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:51 UTC