Bug 1644160 - Use DOM Proxy Expando to hold private fields, rather than allocating Proxy Expando r=jorendorff

Differential Revision: https://phabricator.services.mozilla.com/D83556
This commit is contained in:
Matthew Gaudet 2020-07-20 13:49:10 +00:00
Родитель b56bdc1e4b
Коммит d05eff0349
2 изменённых файлов: 56 добавлений и 0 удалений

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

@ -219,6 +219,45 @@ bool DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy,
return true;
}
bool DOMProxyHandler::definePrivateField(JSContext* cx, HandleObject proxy,
HandleId id,
Handle<PropertyDescriptor> desc,
ObjectOpResult& result) const {
// Delegate to defineProperty, since InitPrivateElemOperation will
// do the pre-existence check for us.
return this->defineProperty(cx, proxy, id, desc, result);
}
bool DOMProxyHandler::setPrivate(JSContext* cx, Handle<JSObject*> proxy,
Handle<jsid> id, Handle<JS::Value> v,
Handle<JS::Value> receiver,
ObjectOpResult& result) const {
// Delegate to set, since SetPrivateElemOperation will
// do the pre-existence check for us.
return this->set(cx, proxy, id, v, receiver, result);
}
bool DOMProxyHandler::getPrivate(JSContext* cx, HandleObject proxy,
HandleValue receiver, HandleId id,
MutableHandleValue vp) const {
// Delegate to set, since GetPrivateElemOperation will
// do the pre-existence check for us.
return this->get(cx, proxy, receiver, id, vp);
}
bool DOMProxyHandler::hasPrivate(JSContext* cx, HandleObject proxy, HandleId id,
bool* bp) const {
JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
// If there is no expando object, then there is no private field.
if (!expando) {
*bp = false;
return true;
}
// Check if the private property is on the expando.
return JS_HasOwnPropertyById(cx, expando, id, bp);
}
bool DOMProxyHandler::set(JSContext* cx, Handle<JSObject*> proxy,
Handle<jsid> id, Handle<JS::Value> v,
Handle<JS::Value> receiver,

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

@ -113,6 +113,23 @@ class DOMProxyHandler : public BaseDOMProxyHandler {
JS::Handle<JS::Value> v, JS::Handle<JS::Value> receiver,
JS::ObjectOpResult& result) const override;
// Override the Private Fields code to instead use the DOM Expando object
// rather than the Proxy Expando object.
virtual bool hasPrivate(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id, bool* bp) const override;
virtual bool getPrivate(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<JS::Value> receiver, JS::Handle<jsid> id,
JS::MutableHandle<JS::Value> vp) const override;
virtual bool setPrivate(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id, JS::Handle<JS::Value> v,
JS::Handle<JS::Value> receiver,
JS::ObjectOpResult& result) const override;
virtual bool definePrivateField(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id,
JS::Handle<JS::PropertyDescriptor> desc,
JS::ObjectOpResult& result) const override;
/*
* If assigning to proxy[id] hits a named setter with OverrideBuiltins or
* an indexed setter, call it and set *done to true on success. Otherwise, set