Closed Bug 1464772 Opened 8 years ago Closed 8 years ago

Make some RealmOptions APIs take a realm instead of compartment

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla62
Tracking Status
firefox62 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

Attachments

(5 files)

No description provided.
At some point I'll audit the obj->realm() calls for CCWs; removing RealmBehaviorsRef(obj) prepares for that. Also, RealmBehaviorsRef(realm) could be removed and we could use RealmBehaviorsRef(cx) everywhere, but it seems reasonable to keep it.
Attachment #8981093 - Flags: review?(luke)
Removes an obj->realm() call, similar to the previous patch.
Attachment #8981097 - Flags: review?(luke)
Inside the JS engine there's no need to call the non-inlined RealmCreationOptionsRef API.
Attachment #8981101 - Flags: review?(luke)
At this point, the only caller of RealmCreationOptionsRef(compartment) is IsSecureContextOrObjectIsFromSecureContext [0]. (Note that we could also use JS::GetIsSecureContext(realm) here, see part 1, but that doesn't really matter.) The first call there can just s/GetContextCompartment/GetContextRealm/. The second one is harder because that wants to know the object's realm, so we need to know if the object can be a CCW. We have the following callers of IsSecureContextOrObjectIsFromSecureContext: (1) ConstructorEnabled in generated bindings. ConstructorEnabled has the following callers: (a) WebIDLGlobalNameHash::GetNames passes a Window, so it should be fine to get its realm. (b) WebIDLGlobalNameHash::DefineIfEnabled does a CheckedUnwrap and then also passes the global object IIUC. (2) nsGlobalWindowInner::OfflineCacheAllowedForContext. Caller is ConstructorEnabled, similar to (1). (3) nsGlobalWindowInner::RegisterProtocolHandlerAllowedForContext. This is stored in PrefableDisablers, see (4). (4) PrefableDisablers::isEnabled. This is called by Prefable::isEnabled, and *that* has about 7 callers [1] and I'm not sure if they can pass wrappers. [0] https://searchfox.org/mozilla-central/rev/b47af5169898b156429c8cdaf415afdaa3c43a7b/dom/bindings/DOMJSClass.h#61 [1] https://searchfox.org/mozilla-central/search?q=symbol:_ZNK7mozilla3dom8Prefable9isEnabledEP9JSContextN2JS6HandleIP8JSObjectEE&redirect=false
Flags: needinfo?(bzbarsky)
(In reply to Jan de Mooij [:jandem] from comment #5) > (2) nsGlobalWindowInner::OfflineCacheAllowedForContext. Caller is > ConstructorEnabled, similar to (1). Oh and this one is also stored in PrefableDisablers, similar to (3).
Attachment #8981093 - Flags: review?(luke) → review+
Attachment #8981097 - Flags: review?(luke) → review+
Attachment #8981101 - Flags: review?(luke) → review+
Comment on attachment 8981088 [details] [diff] [review] Part 1 - Make JS_GetIsSecureContext take a realm instead of compartment and move to JS namespace r=me
Flags: needinfo?(bzbarsky)
Attachment #8981088 - Flags: review?(bzbarsky) → review+
> (2) nsGlobalWindowInner::OfflineCacheAllowedForContext. Caller is ConstructorEnabled, similar to (1). It's a little more complicated than that. This function can be called in two ways: from ConstructorEnabled when looking up the "OfflineResourceList" property on a window and from PrefableDisablers::isEnabled when looking up the "applicationCache" property. This second case falls into (4) from comment 5. > (4) PrefableDisablers::isEnabled. This is called by Prefable::isEnabled, and *that* has about 7 callers [1] and I'm not sure if they can pass wrappers. Right. So looking at those callers: 1) DefinePrefable is called during DOM prototype/constructor setup. The argument is guaranteed to be a DOM prototype, constructor, or instance (in the case of the global) object, 1465602not a wrapper. We could add a MOZ_ASSERT that the incoming object's JSClass tests true for either IsDOMClass() or IsDOMIfaceAndProtoClass(). 2) XrayResolveAttribute has the Xray as "wrapper" and the Xray target as "obj". The latter is never a CCW. 3) XrayResolveMethod, same. 4) XrayResolveConstant, same. 5, 6) XrayAppendPropertyKeys is called from XrayOwnPropertyKeys which has the same setup and is passing "obj" to XrayAppendPropertyKeys. 7) IsGetterEnabled is ... buggy! We don't have great tests for it, so I only tested it by code-inspection. But it won't do the right thing in some cases, precisely because it _can_ pass a cross-compartment wrapper. I filed bug 1465602 on this.
Thanks Boris, that helps a lot. It looks like we can go ahead with this after your patch lands. (In reply to Boris Zbarsky [:bz] (no decent commit message means r-) from comment #8) > This second case falls into (4) from comment 5. See comment 6, FWIW.
Depends on: 1465602
> We could add a MOZ_ASSERT that the incoming object's JSClass tests true for either IsDOMClass() or IsDOMIfaceAndProtoClass() Actually, it could be a plain object too (for the Document case, say). We can definitely assert !js::IsWrapper(), though.
Pushed by jandemooij@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/26cbc312b5cb part 1 - Make JS_GetIsSecureContext take a realm instead of compartment and move to JS namespace. r=bz https://hg.mozilla.org/integration/mozilla-inbound/rev/f58f5333e375 part 2 - Remove RealmBehaviorsRef(obj), change RealmBehaviorsRef(compartment) to take a realm. r=luke https://hg.mozilla.org/integration/mozilla-inbound/rev/e3a6af0b27ec part 3 - Remove unused RealmCreationOptionsRef(obj). r=luke https://hg.mozilla.org/integration/mozilla-inbound/rev/a4187e4b06ee part 4 - Use cx->realm()->creationOptions() instead of RealmCreationOptionsRef in NowAsMillis. r=luke
Still needs a part 5 for RealmCreationOptionsRef(compartment) that we can fix now.
Keywords: leave-open
Also changes RealmCreationOptionsRef to take a realm instead of compartment (this function is now unused but still potentially useful).
Attachment #8982976 - Flags: review?(bzbarsky)
Comment on attachment 8982976 [details] [diff] [review] Part 5 - Use GetIsSecureContext instead of RealmCreationOptionsRef in IsSecureContextOrObjectIsFromSecureContext r=me
Attachment #8982976 - Flags: review?(bzbarsky) → review+
Pushed by jandemooij@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/11aacf3b7e93 part 5 - Use GetIsSecureContext instead of RealmCreationOptionsRef in IsSecureContextOrObjectIsFromSecureContext. r=bz
Keywords: leave-open
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla62
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: