Closed Bug 1471924 Opened 8 years ago Closed 8 years ago

Implement realm switching for Class call/construct hooks

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla63
Tracking Status
firefox63 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

Attachments

(3 files, 1 obsolete file)

These hooks are just JSNatives and it's nice to have the invariant that all JSNatives are called with cx->realm == the callee's realm. Now, we don't want to switch realms for proxies (bug 1297179) and proxies are currently special-cased in JSObject::{callHook,constructHook}. We can do some nice refactoring though to pull the proxy code out of callHook/constructHook and just have InternalCallOrConstruct call Proxy::{call,construct} directly if we have a proxy. After that we can always enter the callee's realm in CallJSNative.
Now CallJSNative is never called for proxy callees so we can simply enter the callee's realm there.
Attachment #8988518 - Flags: review?(luke)
Comment on attachment 8988517 [details] [diff] [review] Part 1 - Stop pretending proxies have a JSNative call/construct hook Review of attachment 8988517 [details] [diff] [review]: ----------------------------------------------------------------- Wow, nice.
Attachment #8988517 - Flags: review?(luke) → review+
Attachment #8988518 - Flags: review?(luke) → review+
Thanks for fixing bug 1331410, too. :-D
(In reply to André Bargull [:anba] from comment #5) > Thanks for fixing bug 1331410, too. :-D \o/
Attached patch Part 3 - Add a proxy testcase (obsolete) — — Splinter Review
It just occurred to me we can actually add a proxy test too. Bug 1297179 should be partially fixed with same-compartment realms (the proxy part, not the bound function part) so I had to see if that test passes now and it does :)
Attachment #8988601 - Flags: review?(andrebargull)
Attachment #8988601 - Attachment is obsolete: true
Attachment #8988601 - Flags: review?(andrebargull)
Attachment #8988604 - Flags: review?(andrebargull)
Comment on attachment 8988604 [details] [diff] [review] Part 3 - Add a proxy testcase Review of attachment 8988604 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/jit-test/tests/realms/proxy-realm.js @@ +2,5 @@ > + > +load(libdir + "asserts.js"); > + > +var g = newGlobal({sameCompartmentAs: this}); > +var {proxy, revoke} = g.eval(`Proxy.revocable(() => {}, {})`); The |new proxy()| case was actually already passing when using an arrow function as the underlying proxy target. Only when the proxy target is actually a constructor, which then makes the proxy a constructor, too, |new proxy()| doesn't throw a TypeError from the correct realm.
Attachment #8988604 - Flags: review?(andrebargull) → review+
(In reply to André Bargull [:anba] from comment #9) > The |new proxy()| case was actually already passing when using an arrow > function as the underlying proxy target. D'oh, good catch. I'll change it to a non-arrow function and verify adding an AutoRealm before the Proxy::construct call breaks the test (I checked this for Proxy::call but not Proxy::construct..).
Pushed by jandemooij@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/da138f7c70ef part 1 - Stop pretending proxies have a JSNative call/construct hook. r=luke https://hg.mozilla.org/integration/mozilla-inbound/rev/0807cc4090d9 part 2 - Enter callee's realm when calling Class call/construct hooks. r=luke https://hg.mozilla.org/integration/mozilla-inbound/rev/a7a4c5bb5efb part 3 - Add a proxy testcase. r=anba
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: