diff --git a/dom/bindings/DOMJSProxyHandler.cpp b/dom/bindings/DOMJSProxyHandler.cpp index 532e9015cab6..4cb4dd1c1e76 100644 --- a/dom/bindings/DOMJSProxyHandler.cpp +++ b/dom/bindings/DOMJSProxyHandler.cpp @@ -219,6 +219,45 @@ bool DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle proxy, return true; } +bool DOMProxyHandler::definePrivateField(JSContext* cx, HandleObject proxy, + HandleId id, + Handle 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 proxy, + Handle id, Handle v, + Handle 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 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 proxy, Handle id, Handle v, Handle receiver, diff --git a/dom/bindings/DOMJSProxyHandler.h b/dom/bindings/DOMJSProxyHandler.h index 3c670b5cfb03..cbeca8d68b2e 100644 --- a/dom/bindings/DOMJSProxyHandler.h +++ b/dom/bindings/DOMJSProxyHandler.h @@ -113,6 +113,23 @@ class DOMProxyHandler : public BaseDOMProxyHandler { JS::Handle v, JS::Handle 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 proxy, + JS::Handle id, bool* bp) const override; + virtual bool getPrivate(JSContext* cx, JS::Handle proxy, + JS::Handle receiver, JS::Handle id, + JS::MutableHandle vp) const override; + virtual bool setPrivate(JSContext* cx, JS::Handle proxy, + JS::Handle id, JS::Handle v, + JS::Handle receiver, + JS::ObjectOpResult& result) const override; + + virtual bool definePrivateField(JSContext* cx, JS::Handle proxy, + JS::Handle id, + JS::Handle 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