From b8e3b65fa750b1d5454e7c43f3754741ace88985 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Thu, 21 Mar 2013 23:23:48 +0100 Subject: [PATCH] Bug 828462 - Root Proxy/Wrapper delete. r=terrence --- dom/base/nsGlobalWindow.cpp | 7 ++++--- dom/bindings/Codegen.py | 4 ++-- dom/bindings/DOMJSProxyHandler.cpp | 3 ++- dom/bindings/DOMJSProxyHandler.h | 3 ++- js/src/jsproxy.cpp | 22 ++++++++-------------- js/src/jsproxy.h | 6 +++--- js/src/jswrapper.cpp | 10 +++++----- js/src/jswrapper.h | 4 ++-- js/src/vm/ScopeObject.cpp | 2 +- js/xpconnect/wrappers/XrayWrapper.cpp | 3 ++- js/xpconnect/wrappers/XrayWrapper.h | 3 ++- 11 files changed, 33 insertions(+), 34 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 5b588b5a8fd..05467335cf0 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -554,7 +554,8 @@ public: virtual bool getOwnPropertyNames(JSContext *cx, JS::Handle proxy, JS::AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, + virtual bool delete_(JSContext *cx, JS::Handle proxy, + JS::Handle id, bool *bp) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *proxy, JS::AutoIdVector &props) MOZ_OVERRIDE; @@ -692,8 +693,8 @@ nsOuterWindowProxy::getOwnPropertyNames(JSContext *cx, JS::Handle pr } bool -nsOuterWindowProxy::delete_(JSContext *cx, JSObject *proxy, jsid id, - bool *bp) +nsOuterWindowProxy::delete_(JSContext *cx, JS::Handle proxy, + JS::Handle id, bool *bp) { if (nsCOMPtr frame = GetSubframeWindow(cx, proxy, id)) { // Reject (which means throw if strict, else return false) the delete. diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 49498b753a5..6d37dac8bf8 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -6212,8 +6212,8 @@ class CGDOMJSProxyHandler_defineProperty(ClassMethod): class CGDOMJSProxyHandler_delete(ClassMethod): def __init__(self, descriptor): - args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'proxy'), - Argument('jsid', 'id'), + args = [Argument('JSContext*', 'cx'), Argument('JS::Handle', 'proxy'), + Argument('JS::Handle', 'id'), Argument('bool*', 'bp')] ClassMethod.__init__(self, "delete_", "bool", args) self.descriptor = descriptor diff --git a/dom/bindings/DOMJSProxyHandler.cpp b/dom/bindings/DOMJSProxyHandler.cpp index 7a7dc6239c2..376139f565a 100644 --- a/dom/bindings/DOMJSProxyHandler.cpp +++ b/dom/bindings/DOMJSProxyHandler.cpp @@ -124,7 +124,8 @@ DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle proxy, JS: } bool -DOMProxyHandler::delete_(JSContext* cx, JSObject* proxy, jsid id, bool* bp) +DOMProxyHandler::delete_(JSContext* cx, JS::Handle proxy, + JS::Handle id, bool* bp) { JSBool b = true; diff --git a/dom/bindings/DOMJSProxyHandler.h b/dom/bindings/DOMJSProxyHandler.h index 69d5be1aad7..43b45ffabc0 100644 --- a/dom/bindings/DOMJSProxyHandler.h +++ b/dom/bindings/DOMJSProxyHandler.h @@ -40,7 +40,8 @@ public: unsigned flags) MOZ_OVERRIDE; bool defineProperty(JSContext* cx, JS::Handle proxy, JS::Handle id, JSPropertyDescriptor* desc) MOZ_OVERRIDE; - bool delete_(JSContext* cx, JSObject* proxy, jsid id, bool* bp) MOZ_OVERRIDE; + bool delete_(JSContext* cx, JS::Handle proxy, + JS::Handle id, bool* bp) MOZ_OVERRIDE; bool enumerate(JSContext* cx, JSObject* proxy, JS::AutoIdVector& props) MOZ_OVERRIDE; bool fix(JSContext* cx, JSObject* proxy, JS::Value* vp); bool has(JSContext* cx, JSObject* proxy, jsid id, bool* bp) MOZ_OVERRIDE; diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp index 29148f1eba6..2e09ff3ef73 100644 --- a/js/src/jsproxy.cpp +++ b/js/src/jsproxy.cpp @@ -498,11 +498,11 @@ DirectProxyHandler::getOwnPropertyNames(JSContext *cx, HandleObject proxy, } bool -DirectProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) +DirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { - RootedValue v(cx); assertEnteredPolicy(cx, proxy, id); RootedObject target(cx, GetProxyTargetObject(proxy)); + RootedValue v(cx); if (!JS_DeletePropertyById2(cx, target, id, v.address())) return false; JSBool b; @@ -810,7 +810,7 @@ class ScriptedIndirectProxyHandler : public BaseProxyHandler { virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); - virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ @@ -912,10 +912,9 @@ ScriptedIndirectProxyHandler::getOwnPropertyNames(JSContext *cx, HandleObject pr } bool -ScriptedIndirectProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id_, bool *bp) +ScriptedIndirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { RootedObject handler(cx, GetIndirectProxyHandlerObject(proxy)); - RootedId id(cx, id_); RootedValue fval(cx), value(cx); return GetFundamentalTrap(cx, handler, cx->names().delete_, &fval) && Trap1(cx, handler, fval, id, value.address()) && @@ -1070,7 +1069,7 @@ class ScriptedDirectProxyHandler : public DirectProxyHandler { virtual bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); - virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) MOZ_OVERRIDE; /* ES5 Harmony derived proxy traps. */ @@ -1726,11 +1725,8 @@ ScriptedDirectProxyHandler::getOwnPropertyNames(JSContext *cx, HandleObject prox // Proxy.[[Delete]](P, Throw) bool -ScriptedDirectProxyHandler::delete_(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) +ScriptedDirectProxyHandler::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { - RootedObject proxy(cx, proxy_); - RootedId id(cx, id_); - // step 1 RootedObject handler(cx, GetDirectProxyHandlerObject(proxy)); @@ -2336,12 +2332,10 @@ Proxy::getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &prop } bool -Proxy::delete_(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) +Proxy::delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) { JS_CHECK_RECURSION(cx, return false); - BaseProxyHandler *handler = GetProxyHandler(proxy_); - RootedObject proxy(cx, proxy_); - RootedId id(cx, id_); + BaseProxyHandler *handler = GetProxyHandler(proxy); *bp = true; // default result if we refuse to perform this action AutoEnterPolicy policy(cx, handler, proxy, id, BaseProxyHandler::SET, true); if (!policy.allowed()) diff --git a/js/src/jsproxy.h b/js/src/jsproxy.h index 316557654f5..40025276588 100644 --- a/js/src/jsproxy.h +++ b/js/src/jsproxy.h @@ -113,7 +113,7 @@ class JS_FRIEND_API(BaseProxyHandler) { PropertyDescriptor *desc) = 0; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props) = 0; - virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) = 0; + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) = 0; virtual bool enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) = 0; @@ -167,7 +167,7 @@ public: PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, JSObject *proxy, jsid id, + virtual bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) MOZ_OVERRIDE; @@ -218,7 +218,7 @@ class Proxy { static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, PropertyDescriptor *desc); static bool defineProperty(JSContext *cx, HandleObject proxy, HandleId id, HandleValue v); static bool getOwnPropertyNames(JSContext *cx, HandleObject proxy, AutoIdVector &props); - static bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp); + static bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp); static bool enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props); /* ES5 Harmony derived proxy traps. */ diff --git a/js/src/jswrapper.cpp b/js/src/jswrapper.cpp index c9eb269fa41..1279bd355ba 100644 --- a/js/src/jswrapper.cpp +++ b/js/src/jswrapper.cpp @@ -276,12 +276,12 @@ CrossCompartmentWrapper::getOwnPropertyNames(JSContext *cx, HandleObject wrapper } bool -CrossCompartmentWrapper::delete_(JSContext *cx, JSObject *wrapperArg, jsid id, bool *bp) +CrossCompartmentWrapper::delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) { - RootedObject wrapper(cx, wrapperArg); + RootedId idCopy(cx, id); PIERCE(cx, wrapper, - cx->compartment->wrapId(cx, &id), - Wrapper::delete_(cx, wrapper, id, bp), + cx->compartment->wrapId(cx, idCopy.address()), + Wrapper::delete_(cx, wrapper, idCopy, bp), NOTHING); } @@ -734,7 +734,7 @@ DeadObjectProxy::getOwnPropertyNames(JSContext *cx, HandleObject wrapper, } bool -DeadObjectProxy::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) +DeadObjectProxy::delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) { JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_DEAD_OBJECT); return false; diff --git a/js/src/jswrapper.h b/js/src/jswrapper.h index f0144813de4..83e54554d92 100644 --- a/js/src/jswrapper.h +++ b/js/src/jswrapper.h @@ -94,7 +94,7 @@ class JS_FRIEND_API(CrossCompartmentWrapper) : public Wrapper PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE; /* ES5 Harmony derived wrapper traps. */ @@ -171,7 +171,7 @@ class JS_FRIEND_API(DeadObjectProxy) : public BaseProxyHandler PropertyDescriptor *desc) MOZ_OVERRIDE; virtual bool getOwnPropertyNames(JSContext *cx, HandleObject wrapper, AutoIdVector &props) MOZ_OVERRIDE; - virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) MOZ_OVERRIDE; + virtual bool delete_(JSContext *cx, HandleObject wrapper, HandleId id, bool *bp) MOZ_OVERRIDE; virtual bool enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props) MOZ_OVERRIDE; /* Spidermonkey extensions. */ diff --git a/js/src/vm/ScopeObject.cpp b/js/src/vm/ScopeObject.cpp index 5cf8a6b053f..ea9825416a2 100644 --- a/js/src/vm/ScopeObject.cpp +++ b/js/src/vm/ScopeObject.cpp @@ -1469,7 +1469,7 @@ class DebugScopeProxy : public BaseProxyHandler return true; } - bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp) MOZ_OVERRIDE + bool delete_(JSContext *cx, HandleObject proxy, HandleId id, bool *bp) MOZ_OVERRIDE { RootedValue idval(cx, IdToValue(id)); return js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_CANT_DELETE, diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 40b96310f2e..1bb9bcef782 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -1668,7 +1668,8 @@ XrayWrapper::getOwnPropertyNames(JSContext *cx, JS::Handle bool -XrayWrapper::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp) +XrayWrapper::delete_(JSContext *cx, JS::Handle wrapper, + JS::Handle id, bool *bp) { assertEnteredPolicy(cx, wrapper, id); // Redirect access straight to the wrapper if we should be transparent. diff --git a/js/xpconnect/wrappers/XrayWrapper.h b/js/xpconnect/wrappers/XrayWrapper.h index b175347a260..0e9a4c18966 100644 --- a/js/xpconnect/wrappers/XrayWrapper.h +++ b/js/xpconnect/wrappers/XrayWrapper.h @@ -75,7 +75,8 @@ class XrayWrapper : public Base { js::PropertyDescriptor *desc); virtual bool getOwnPropertyNames(JSContext *cx, JS::Handle wrapper, js::AutoIdVector &props); - virtual bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp); + virtual bool delete_(JSContext *cx, JS::Handle wrapper, + JS::Handle id, bool *bp); virtual bool enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props); /* Derived proxy traps. */