From c72d0f8113434d3e6e97236c2c410f21d0507263 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 31 May 2013 10:36:01 -0700 Subject: [PATCH] Bug 858101 - Run the DefaultValue algorithm directly on the wrapper for Xrays. r=mrbkap --- js/src/jsfriendapi.h | 5 +++++ js/src/jsobj.cpp | 2 +- js/src/jsobj.h | 4 ---- js/xpconnect/wrappers/XrayWrapper.cpp | 14 ++++++++++++++ js/xpconnect/wrappers/XrayWrapper.h | 4 ++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 182c0229a39..acb8db2e374 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -1717,6 +1717,11 @@ SetObjectMetadata(JSContext *cx, JSHandleObject obj, JSHandleObject metadata); JS_FRIEND_API(JSObject *) GetObjectMetadata(JSObject *obj); +/* ES5 8.12.8. */ +extern JS_FRIEND_API(JSBool) +DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); + + } /* namespace js */ extern JS_FRIEND_API(JSBool) diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index 97c12cad4e0..28247640951 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -4609,7 +4609,7 @@ MaybeCallMethod(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue return Invoke(cx, ObjectValue(*obj), vp, 0, NULL, vp.address()); } -JSBool +JS_FRIEND_API(JSBool) js::DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) { JS_ASSERT(hint == JSTYPE_NUMBER || hint == JSTYPE_STRING || hint == JSTYPE_VOID); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 66802779eef..2eab87d3e27 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -203,10 +203,6 @@ DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, JSBool *succeeded); } /* namespace js::baseops */ -/* ES5 8.12.8. */ -extern JSBool -DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp); - extern Class ArrayClass; extern Class ArrayBufferClass; extern Class BlockClass; diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index d7a4a07236a..97958dc0908 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -1885,6 +1885,20 @@ XrayWrapper::construct(JSContext *cx, HandleObject wrapper, const return Traits::construct(cx, wrapper, args, Base::singleton); } +template +bool +XrayWrapper::defaultValue(JSContext *cx, HandleObject wrapper, + JSType hint, MutableHandleValue vp) +{ + // Even if this isn't a security wrapper, Xray semantics dictate that we + // run the DefaultValue algorithm directly on the Xray wrapper. + // + // NB: We don't have to worry about things with special [[DefaultValue]] + // behavior like Date because we'll never have an XrayWrapper to them. + return js::DefaultValue(cx, wrapper, hint, vp); +} + + /* * The Permissive / Security variants should be used depending on whether the * compartment of the wrapper is guranteed to subsume the compartment of the diff --git a/js/xpconnect/wrappers/XrayWrapper.h b/js/xpconnect/wrappers/XrayWrapper.h index 1df5839eb06..6268a061eef 100644 --- a/js/xpconnect/wrappers/XrayWrapper.h +++ b/js/xpconnect/wrappers/XrayWrapper.h @@ -103,6 +103,10 @@ class XrayWrapper : public Base { virtual bool construct(JSContext *cx, JS::Handle wrapper, const JS::CallArgs &args) MOZ_OVERRIDE; + virtual bool defaultValue(JSContext *cx, JS::HandleObject wrapper, + JSType hint, JS::MutableHandleValue vp) + MOZ_OVERRIDE; + static XrayWrapper singleton; private: