Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify in which Realm records, record arrays, and associated objects are created #3

Open
ajklein opened this issue Dec 12, 2014 · 11 comments

Comments

@ajklein
Copy link
Collaborator

ajklein commented Dec 12, 2014

The current spec is silent on this, which will cause records to be created in the Realm of the function where object mutation occurs, record arrays to be created who-knows-where (maybe in the Realm of the first mutation per observer?).

The V8 implementation diverges from this by using the Realm V8 internally associates with the observed object for all such creations.

@arv
Copy link
Owner

arv commented Dec 15, 2014

What should happen in the following scenario?

// realm-a
var object = ...
function callbackA(records) {}
Object.observe(object, callbackA);

// realm-b
var object = realmA.object;
function callbackB(records) {}
Object.observe(obj, callbackB);

// realm-c
realmA.object.x = 42;

Does callbackA and callbackB get the same array of records?

@arv
Copy link
Owner

arv commented Dec 15, 2014

One possible solution is that callbackA and callbackB do not get the same array or the same records and that we always create that array and records in the realm of the callback.

@ajklein
Copy link
Collaborator Author

ajklein commented Dec 15, 2014

What about two different observers in the same realm? I think you'd want them to share records if possible (to avoid unnecessary record allocations).

@arv
Copy link
Owner

arv commented Dec 15, 2014

Yes. Same. I was thinking we would get the [[Realm]] of the callback function and use that to determine which realm to create the array and records for.

@arv
Copy link
Owner

arv commented Jan 14, 2015

@domenic suggested using the [[Realm]] of the Object.observe function. I'll provide a PR for that.

@ajklein
Copy link
Collaborator Author

ajklein commented Jan 14, 2015

There can be multiple Object.observe functions per object, just as there can be observer functions from multiple realms. I'm not clear on how @domenic's suggestion gives a clear answer about which [[Realm]] To use.

@arv
Copy link
Owner

arv commented Jan 14, 2015

Yeah. It is not obvious. I'm going to create a branch and see how it works out.

@domenic
Copy link
Contributor

domenic commented Jan 14, 2015

My thinking (which was pretty cursory) is that when someone does

Object.observe(objFromOtherRealm, function (records) {
});

they expect the records to have Object.prototype from the current realm, i.e.

assert(Object.getPrototypeOf(records[0]) === Object.prototype)

@arv
Copy link
Owner

arv commented Jan 14, 2015

Or?

assert(Object.getPrototypeOf(records[0]) === callbackFunction.__proto__.__proto_)

the callbackFunction might come from a different realm too

@arv
Copy link
Owner

arv commented Jan 14, 2015

Another issue is.

windowA.Object.getNotifier(obj) === windowB.Object.getNotifier(obj);  // ?

I think this must be false due to ocap.

@domenic
Copy link
Contributor

domenic commented Jan 14, 2015

Between the realm of the Object.observe call and the realm of the callback function, I don't see a compelling preference either way. Mainly because I have a hard time imagining a reasonable scenario where they would be different. (Whereas, it's easy to imagine the scenario of observing an object from a different realm.)

So given that, I would say between those two choose whichever makes the spec and implementation easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants