Bug 1673553 part 74 - Remove NewSingletonProxyObject. r=iain

Depends on D98505

Differential Revision: https://phabricator.services.mozilla.com/D98506
This commit is contained in:
Jan de Mooij 2020-12-02 20:38:21 +00:00
Родитель d08386a27e
Коммит 4dd5ca7fdd
7 изменённых файлов: 4 добавлений и 121 удалений

Просмотреть файл

@ -250,13 +250,9 @@ JSObject* WindowNamedPropertiesHandler::Create(JSContext* aCx,
js::ProxyOptions options;
options.setClass(&WindowNamedPropertiesClass.mBase);
// Note: since the scope polluter proxy lives on the window's prototype
// chain, it needs a singleton type to avoid polluting type information
// for properties on the window.
JS::Rooted<JSObject*> gsp(
aCx, js::NewSingletonProxyObject(
aCx, WindowNamedPropertiesHandler::getInstance(),
JS::NullHandleValue, aProto, options));
aCx, js::NewProxyObject(aCx, WindowNamedPropertiesHandler::getInstance(),
JS::NullHandleValue, aProto, options));
if (!gsp) {
return nullptr;
}

Просмотреть файл

@ -583,10 +583,6 @@ JS_FRIEND_API JSObject* NewProxyObject(
JSContext* cx, const BaseProxyHandler* handler, JS::HandleValue priv,
JSObject* proto, const ProxyOptions& options = ProxyOptions());
JS_FRIEND_API JSObject* NewSingletonProxyObject(
JSContext* cx, const BaseProxyHandler* handler, JS::HandleValue priv,
JSObject* proto, const ProxyOptions& options = ProxyOptions());
JSObject* RenewProxyObject(JSContext* cx, JSObject* obj,
BaseProxyHandler* handler, const JS::Value& priv);

Просмотреть файл

@ -391,7 +391,7 @@ ModuleNamespaceObject* ModuleNamespaceObject::create(
options.setLazyProto(true);
Rooted<UniquePtr<IndirectBindingMap>> rootedBindings(cx, std::move(bindings));
RootedObject object(
cx, NewSingletonProxyObject(cx, &proxyHandler, priv, nullptr, options));
cx, NewProxyObject(cx, &proxyHandler, priv, nullptr, options));
if (!object) {
return nullptr;
}

Просмотреть файл

@ -959,30 +959,6 @@ JS_FRIEND_API JSObject* js::NewProxyObject(JSContext* cx,
options.clasp());
}
JS_FRIEND_API JSObject* js::NewSingletonProxyObject(
JSContext* cx, const BaseProxyHandler* handler, HandleValue priv,
JSObject* proto_, const ProxyOptions& options) {
AssertHeapIsIdle();
CHECK_THREAD(cx);
// This can be called from the compartment wrap hooks while in a realm with a
// gray global. Trigger the read barrier on the global to ensure this is
// unmarked.
cx->realm()->maybeGlobal();
if (proto_ != TaggedProto::LazyProto) {
cx->check(proto_); // |priv| might be cross-compartment.
}
if (options.lazyProto()) {
MOZ_ASSERT(!proto_);
proto_ = TaggedProto::LazyProto;
}
return ProxyObject::NewSingleton(cx, handler, priv, TaggedProto(proto_),
options.clasp());
}
void ProxyObject::renew(const BaseProxyHandler* handler, const Value& priv) {
MOZ_ASSERT(!IsInsideNursery(this));
MOZ_ASSERT_IF(IsCrossCompartmentWrapper(this), IsDeadProxyObject(this));

Просмотреть файл

@ -295,7 +295,7 @@ JSObject* Wrapper::NewSingleton(JSContext* cx, JSObject* obj,
ar.emplace(cx, &cx->compartment()->globalForNewCCW());
}
RootedValue priv(cx, ObjectValue(*obj));
return NewSingletonProxyObject(cx, handler, priv, options.proto(), options);
return NewProxyObject(cx, handler, priv, options.proto(), options);
}
JSObject* Wrapper::Renew(JSObject* existing, JSObject* obj,

Просмотреть файл

@ -145,86 +145,6 @@ ProxyObject* ProxyObject::New(JSContext* cx, const BaseProxyHandler* handler,
return proxy;
}
/* static */
ProxyObject* ProxyObject::NewSingleton(JSContext* cx,
const BaseProxyHandler* handler,
HandleValue priv, TaggedProto proto_,
const JSClass* clasp) {
Rooted<TaggedProto> proto(cx, proto_);
MOZ_ASSERT(clasp->isProxy());
MOZ_ASSERT(isValidProxyClass(clasp));
MOZ_ASSERT(clasp->shouldDelayMetadataBuilder());
MOZ_ASSERT_IF(proto.isObject(),
cx->compartment() == proto.toObject()->compartment());
MOZ_ASSERT(clasp->hasFinalize());
#ifdef DEBUG
if (priv.isGCThing()) {
JS::AssertCellIsNotGray(priv.toGCThing());
}
#endif
gc::AllocKind allocKind = GetProxyGCObjectKind(clasp, handler, priv);
AutoSetNewObjectMetadata metadata(cx);
Rooted<ProxyObject*> proxy(cx);
{
Realm* realm = cx->realm();
// We're creating a singleton, so go straight to getting a singleton group,
// from the singleton group cache (or creating it freshly if needed).
RootedObjectGroup group(cx, ObjectGroup::lazySingletonGroup(
cx, ObjectGroupRealm::getForNewObject(cx),
realm, clasp, proto));
if (!group) {
return nullptr;
}
MOZ_ASSERT(group->realm() == realm);
MOZ_ASSERT(group->singleton());
MOZ_ASSERT(!IsAboutToBeFinalizedUnbarriered(group.address()));
// Also retrieve an empty shape. Unlike for non-singleton proxies, this
// shape lookup is not cached in |realm->newProxyCache|. We could cache it
// there, but distinguishing group/shape for singleton and non-singleton
// proxies would increase contention on the cache (and might end up evicting
// non-singleton cases where performance really matters). Assume that
// singleton proxies are rare, and don't bother caching their shapes/groups.
RootedShape shape(
cx, EmptyShape::getInitialShape(cx, clasp, proto, /* nfixed = */ 0));
if (!shape) {
return nullptr;
}
MOZ_ASSERT(shape->zone() == cx->zone());
MOZ_ASSERT(!IsAboutToBeFinalizedUnbarriered(shape.address()));
gc::InitialHeap heap = gc::TenuredHeap;
debugCheckNewObject(group, shape, allocKind, heap);
JSObject* obj =
AllocateObject(cx, allocKind, /* nDynamicSlots = */ 0, heap, clasp);
if (!obj) {
return nullptr;
}
proxy = static_cast<ProxyObject*>(obj);
proxy->initGroup(group);
proxy->initShape(shape);
MOZ_ASSERT(clasp->shouldDelayMetadataBuilder());
realm->setObjectPendingMetadata(cx, proxy);
js::gc::gcprobes::CreateObject(proxy);
}
proxy->init(handler, priv, cx);
MOZ_ASSERT(proxy->isSingleton());
return proxy;
}
gc::AllocKind ProxyObject::allocKindForTenure() const {
MOZ_ASSERT(usingInlineValueArray());
Value priv = private_();

Просмотреть файл

@ -43,11 +43,6 @@ class ProxyObject : public JSObject {
HandleValue priv, TaggedProto proto_,
const JSClass* clasp);
static ProxyObject* NewSingleton(JSContext* cx,
const BaseProxyHandler* handler,
HandleValue priv, TaggedProto proto_,
const JSClass* clasp);
void init(const BaseProxyHandler* handler, HandleValue priv, JSContext* cx);
// Proxies usually store their ProxyValueArray inline in the object.