From ef7a22ceb73bc991f06c57acdeae7c01900c866b Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Thu, 18 Dec 2014 05:02:30 -0600 Subject: [PATCH] Bug 1112778, part 2 - Rename js::DefaultValue -> js::OrdinaryToPrimitive. r=Waldo. --HG-- extra : rebase_source : 90e9de457d157d0ac30308ceb633f981917645ff --- js/src/jsapi.cpp | 8 -------- js/src/jsapi.h | 3 ++- js/src/jsdate.cpp | 2 +- js/src/jsfriendapi.h | 4 ---- js/src/jsobj.cpp | 17 +++++++++++++++-- js/src/jsobj.h | 12 +----------- js/src/proxy/BaseProxyHandler.cpp | 2 +- js/src/proxy/SecurityWrapper.cpp | 4 ++-- js/xpconnect/src/Sandbox.cpp | 2 +- js/xpconnect/wrappers/XrayWrapper.cpp | 4 ++-- 10 files changed, 25 insertions(+), 33 deletions(-) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index a9266f265c08..2fc4065c380b 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -1941,14 +1941,6 @@ JS_ResolveStub(JSContext *cx, HandleObject obj, HandleId id, bool *resolvedp) } #endif /* GCC 4.4 */ -JS_PUBLIC_API(bool) -JS::OrdinaryToPrimitive(JSContext *cx, HandleObject obj, JSType type, MutableHandleValue vp) -{ - MOZ_ASSERT(type != JSTYPE_OBJECT && type != JSTYPE_FUNCTION); - MOZ_ASSERT(obj); - return DefaultValue(cx, obj, type, vp); -} - JS_PUBLIC_API(JSObject *) JS_InitClass(JSContext *cx, HandleObject obj, HandleObject parent_proto, const JSClass *clasp, JSNative constructor, unsigned nargs, diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 0d8316d7be59..f2c7fe7f2892 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -1199,7 +1199,8 @@ ToObject(JSContext *cx, HandleValue vp) * as a fallback. */ extern JS_PUBLIC_API(bool) -OrdinaryToPrimitive(JSContext *cx, HandleObject obj, JSType type, MutableHandleValue vp); +OrdinaryToPrimitive(JSContext *cx, JS::HandleObject obj, JSType type, + JS::MutableHandleValue vp); } /* namespace JS */ diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 2f798bf16027..8e6b81c29d62 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -522,7 +522,7 @@ date_convert(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp MOZ_ASSERT(hint == JSTYPE_NUMBER || hint == JSTYPE_STRING || hint == JSTYPE_VOID); MOZ_ASSERT(obj->is()); - return DefaultValue(cx, obj, (hint == JSTYPE_VOID) ? JSTYPE_STRING : hint, vp); + return JS::OrdinaryToPrimitive(cx, obj, hint == JSTYPE_VOID ? JSTYPE_STRING : hint, vp); } /* for use by date_parse */ diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 08d58bd91719..14e1bd50f19c 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -2530,10 +2530,6 @@ GetElementsWithAdder(JSContext *cx, JS::HandleObject obj, JS::HandleObject recei JS_FRIEND_API(bool) ForwardToNative(JSContext *cx, JSNative native, const JS::CallArgs &args); -/* ES5 8.12.8. */ -extern JS_FRIEND_API(bool) -DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp); - /* * Helper function. To approximate a call to the [[DefineOwnProperty]] internal * method described in ES5, first call this, then call JS_DefinePropertyById. diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index f011faeb4157..32afc8ab8346 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -3229,6 +3229,19 @@ JSObject::reportNotExtensible(JSContext *cx, unsigned report) nullptr, nullptr); } +/* static */ bool +JSObject::defaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) +{ + JSConvertOp op = obj->getClass()->convert; + bool ok; + if (!op) + ok = JS::OrdinaryToPrimitive(cx, obj, hint, vp); + else + ok = op(cx, obj, hint, vp); + MOZ_ASSERT_IF(ok, vp.isPrimitive()); + return ok; +} + bool JSObject::callMethod(JSContext *cx, HandleId id, unsigned argc, Value *argv, MutableHandleValue vp) { @@ -3332,8 +3345,8 @@ MaybeCallMethod(JSContext *cx, HandleObject obj, HandleId id, MutableHandleValue return Invoke(cx, ObjectValue(*obj), vp, 0, nullptr, vp); } -JS_FRIEND_API(bool) -js::DefaultValue(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) +bool +JS::OrdinaryToPrimitive(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp) { MOZ_ASSERT(hint == JSTYPE_NUMBER || hint == JSTYPE_STRING || hint == JSTYPE_VOID); diff --git a/js/src/jsobj.h b/js/src/jsobj.h index 08557cf9b284..f5453df5ee7a 100644 --- a/js/src/jsobj.h +++ b/js/src/jsobj.h @@ -673,17 +673,7 @@ class JSObject : public js::gc::Cell static inline bool unwatch(JSContext *cx, JS::HandleObject obj, JS::HandleId id); static bool defaultValue(JSContext *cx, js::HandleObject obj, JSType hint, - js::MutableHandleValue vp) - { - JSConvertOp op = obj->getClass()->convert; - bool ok; - if (!op) - ok = js::DefaultValue(cx, obj, hint, vp); - else - ok = op(cx, obj, hint, vp); - MOZ_ASSERT_IF(ok, vp.isPrimitive()); - return ok; - } + js::MutableHandleValue vp); static JSObject *thisObject(JSContext *cx, js::HandleObject obj) { diff --git a/js/src/proxy/BaseProxyHandler.cpp b/js/src/proxy/BaseProxyHandler.cpp index a71d729af3ec..1db34d369bb2 100644 --- a/js/src/proxy/BaseProxyHandler.cpp +++ b/js/src/proxy/BaseProxyHandler.cpp @@ -291,7 +291,7 @@ bool BaseProxyHandler::defaultValue(JSContext *cx, HandleObject proxy, JSType hint, MutableHandleValue vp) const { - return DefaultValue(cx, proxy, hint, vp); + return OrdinaryToPrimitive(cx, proxy, hint, vp); } bool diff --git a/js/src/proxy/SecurityWrapper.cpp b/js/src/proxy/SecurityWrapper.cpp index 13e7f663e19f..3a739bd4b3ae 100644 --- a/js/src/proxy/SecurityWrapper.cpp +++ b/js/src/proxy/SecurityWrapper.cpp @@ -69,7 +69,7 @@ SecurityWrapper::isExtensible(JSContext *cx, HandleObject wrapper, bool *e return true; } -// For security wrappers, we run the DefaultValue algorithm on the wrapper +// For security wrappers, we run the OrdinaryToPrimitive algorithm on the wrapper // itself, which means that the existing security policy on operations like // toString() will take effect and do the right thing here. template @@ -77,7 +77,7 @@ bool SecurityWrapper::defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, MutableHandleValue vp) const { - return DefaultValue(cx, wrapper, hint, vp); + return OrdinaryToPrimitive(cx, wrapper, hint, vp); } template diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 01de9be692f7..e7354b995506 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -359,7 +359,7 @@ sandbox_convert(JSContext *cx, HandleObject obj, JSType type, MutableHandleValue return true; } - return JS::OrdinaryToPrimitive(cx, obj, type, vp); + return OrdinaryToPrimitive(cx, obj, type, vp); } static bool diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index e5cc882d39d5..a7d11ae12c4b 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -2150,11 +2150,11 @@ XrayWrapper::defaultValue(JSContext *cx, HandleObject wrapper, JSType hint, MutableHandleValue vp) const { // Even if this isn't a security wrapper, Xray semantics dictate that we - // run the DefaultValue algorithm directly on the Xray wrapper. + // run the OrdinaryToPrimitive 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); + return OrdinaryToPrimitive(cx, wrapper, hint, vp); } template