mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
Bug 1571021 - Remove use of CrossCompartmentKey from putWrapper APIs r=jandem?
Differential Revision: https://phabricator.services.mozilla.com/D41181 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ac65366274
commit
fd6533075c
@ -725,8 +725,7 @@ JS_PUBLIC_API JSObject* JS_TransplantObject(JSContext* cx, HandleObject origobj,
|
||||
JSObject::swap(cx, origobj, newIdentityWrapper);
|
||||
if (origobj->compartment()->lookupWrapper(newIdentity)) {
|
||||
MOZ_ASSERT(origobj->is<CrossCompartmentWrapperObject>());
|
||||
if (!origobj->compartment()->putWrapper(
|
||||
cx, CrossCompartmentKey(newIdentity), origv)) {
|
||||
if (!origobj->compartment()->putWrapper(cx, newIdentity, origv)) {
|
||||
MOZ_CRASH();
|
||||
}
|
||||
}
|
||||
|
@ -593,8 +593,7 @@ void js::RemapWrapper(JSContext* cx, JSObject* wobjArg,
|
||||
|
||||
// Update the entry in the compartment's wrapper map to point to the old
|
||||
// wrapper, which has now been updated (via reuse or swap).
|
||||
if (!wcompartment->putWrapper(cx, CrossCompartmentKey(newTarget),
|
||||
ObjectValue(*wobj))) {
|
||||
if (!wcompartment->putWrapper(cx, newTarget, ObjectValue(*wobj))) {
|
||||
oomUnsafe.crash("js::RemapWrapper");
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,6 @@ bool Compartment::wrap(JSContext* cx, MutableHandleString strp) {
|
||||
}
|
||||
|
||||
/* Check the cache. */
|
||||
RootedValue key(cx, StringValue(str));
|
||||
if (WrapperMap::Ptr p = lookupWrapper(str)) {
|
||||
strp.set(p->value().get().toString());
|
||||
return true;
|
||||
@ -172,7 +171,7 @@ bool Compartment::wrap(JSContext* cx, MutableHandleString strp) {
|
||||
if (!copy) {
|
||||
return false;
|
||||
}
|
||||
if (!putWrapper(cx, CrossCompartmentKey(key), StringValue(copy))) {
|
||||
if (!putWrapper(cx, strp, StringValue(copy))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -287,7 +286,6 @@ bool Compartment::getNonWrapperObjectForCurrentCompartment(
|
||||
bool Compartment::getOrCreateWrapper(JSContext* cx, HandleObject existing,
|
||||
MutableHandleObject obj) {
|
||||
// If we already have a wrapper for this value, use it.
|
||||
RootedValue key(cx, ObjectValue(*obj));
|
||||
if (WrapperMap::Ptr p = lookupWrapper(obj)) {
|
||||
obj.set(&p->value().get().toObject());
|
||||
MOZ_ASSERT(obj->is<CrossCompartmentWrapperObject>());
|
||||
@ -307,9 +305,9 @@ bool Compartment::getOrCreateWrapper(JSContext* cx, HandleObject existing,
|
||||
|
||||
// We maintain the invariant that the key in the cross-compartment wrapper
|
||||
// map is always directly wrapped by the value.
|
||||
MOZ_ASSERT(Wrapper::wrappedObject(wrapper) == &key.get().toObject());
|
||||
MOZ_ASSERT(Wrapper::wrappedObject(wrapper) == obj);
|
||||
|
||||
if (!putWrapper(cx, CrossCompartmentKey(key), ObjectValue(*wrapper))) {
|
||||
if (!putWrapper(cx, obj, ObjectValue(*wrapper))) {
|
||||
// Enforce the invariant that all cross-compartment wrapper object are
|
||||
// in the map by nuking the wrapper if we couldn't add it.
|
||||
// Unfortunately it's possible for the wrapper to still be marked if we
|
||||
|
@ -426,6 +426,10 @@ class JS::Compartment {
|
||||
bool getOrCreateWrapper(JSContext* cx, js::HandleObject existing,
|
||||
js::MutableHandleObject obj);
|
||||
|
||||
MOZ_MUST_USE bool putWrapper(JSContext* cx,
|
||||
const js::CrossCompartmentKey& wrapped,
|
||||
const js::Value& wrapper);
|
||||
|
||||
public:
|
||||
explicit Compartment(JS::Zone* zone, bool invisibleToDebugger);
|
||||
|
||||
@ -443,9 +447,15 @@ class JS::Compartment {
|
||||
MOZ_MUST_USE bool rewrap(JSContext* cx, JS::MutableHandleObject obj,
|
||||
JS::HandleObject existing);
|
||||
|
||||
MOZ_MUST_USE bool putWrapper(JSContext* cx,
|
||||
const js::CrossCompartmentKey& wrapped,
|
||||
const js::Value& wrapper);
|
||||
MOZ_MUST_USE bool putWrapper(JSContext* cx, JSObject* wrapped,
|
||||
const js::Value& wrapper) {
|
||||
return putWrapper(cx, js::CrossCompartmentKey(wrapped), wrapper);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE bool putWrapper(JSContext* cx, JSString* wrapped,
|
||||
const js::Value& wrapper) {
|
||||
return putWrapper(cx, js::CrossCompartmentKey(wrapped), wrapper);
|
||||
}
|
||||
|
||||
js::WrapperMap::Ptr lookupWrapper(JSObject* obj) const {
|
||||
return crossCompartmentWrappers.lookup(js::CrossCompartmentKey(obj));
|
||||
|
Loading…
Reference in New Issue
Block a user