Bug 1112778, part 2 - Rename js::DefaultValue -> js::OrdinaryToPrimitive. r=Waldo.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 18 Dec 2014 05:02:30 -0600
changeset 251146 ec05328eb3252d9adc6529e47f6f5b428959fa09
parent 251145 c51dcd10c79eec9d1725bab1508e4cd714e5b590
child 251147 42e833ab7dea24b06adf2a374b4dadacec777387
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1112778
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1112778, part 2 - Rename js::DefaultValue -> js::OrdinaryToPrimitive. r=Waldo.
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jsdate.cpp
js/src/jsfriendapi.h
js/src/jsobj.cpp
js/src/jsobj.h
js/src/proxy/BaseProxyHandler.cpp
js/src/proxy/SecurityWrapper.cpp
js/xpconnect/src/Sandbox.cpp
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1936,24 +1936,16 @@ JS_StrictPropertyStub(JSContext *cx, Han
 JS_PUBLIC_API(bool)
 JS_ResolveStub(JSContext *cx, HandleObject obj, HandleId id, bool *resolvedp)
 {
     MOZ_ASSERT(*resolvedp == false);
     return true;
 }
 #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,
              const JSPropertySpec *ps, const JSFunctionSpec *fs,
              const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1194,17 +1194,18 @@ ToObject(JSContext *cx, HandleValue vp)
  * Implements ES6 draft rev 28 (2014 Oct 14) 7.1.1, second algorithm.
  *
  * Most users should not call this -- use JS::ToNumber, ToBoolean, or ToString
  * instead. This should only be called from custom convert hooks. It implements
  * the default conversion behavior shared by most objects in JS, so it's useful
  * 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 */
 
 extern JS_PUBLIC_API(bool)
 JS_DoubleIsInt32(double d, int32_t *ip);
 
 extern JS_PUBLIC_API(int32_t)
 JS_DoubleToInt32(double d);
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -517,17 +517,17 @@ MakeTime(double hour, double min, double
  */
 
 static bool
 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<DateObject>());
 
-    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 */
 
 static const char* const wtb[] = {
     "am", "pm",
     "monday", "tuesday", "wednesday", "thursday", "friday",
     "saturday", "sunday",
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -2525,20 +2525,16 @@ GetObjectMetadata(JSObject *obj);
 
 JS_FRIEND_API(bool)
 GetElementsWithAdder(JSContext *cx, JS::HandleObject obj, JS::HandleObject receiver,
                      uint32_t begin, uint32_t end, js::ElementAdder *adder);
 
 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.
  *
  * JS_DefinePropertyById by itself does not enforce the invariants on
  * non-configurable properties when obj->isNative(). This function performs the
  * relevant checks (specified in ES5 8.12.9 [[DefineOwnProperty]] steps 1-11),
  * but only if obj is native.
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -3224,16 +3224,29 @@ bool
 JSObject::reportNotExtensible(JSContext *cx, unsigned report)
 {
     RootedValue val(cx, ObjectValue(*this));
     return js_ReportValueErrorFlags(cx, report, JSMSG_OBJECT_NOT_EXTENSIBLE,
                                     JSDVG_IGNORE_STACK, val, js::NullPtr(),
                                     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)
 {
     RootedValue fval(cx);
     RootedObject obj(cx, this);
     if (!JSObject::getGeneric(cx, obj, obj, id, &fval))
         return false;
     return Invoke(cx, ObjectValue(*obj), fval, argc, argv, vp);
@@ -3327,18 +3340,18 @@ MaybeCallMethod(JSContext *cx, HandleObj
         return false;
     if (!IsCallable(vp)) {
         vp.setObject(*obj);
         return true;
     }
     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);
 
     Rooted<jsid> id(cx);
 
     const Class *clasp = obj->getClass();
     if (hint == JSTYPE_STRING) {
         id = NameToId(cx->names().toString);
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -668,27 +668,17 @@ class JSObject : public js::gc::Cell
     static inline bool deleteElement(JSContext *cx, js::HandleObject obj, uint32_t index,
                                      bool *succeeded);
 
     static inline bool watch(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
                              JS::HandleObject callable);
     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)
     {
         if (js::ObjectOp op = obj->getOps()->thisObject)
             return op(cx, obj);
         return obj;
     }
 
--- a/js/src/proxy/BaseProxyHandler.cpp
+++ b/js/src/proxy/BaseProxyHandler.cpp
@@ -286,17 +286,17 @@ BaseProxyHandler::boxedValue_unbox(JSCon
     vp.setUndefined();
     return true;
 }
 
 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
 BaseProxyHandler::nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl,
                              CallArgs args) const
 {
     ReportIncompatible(cx, args);
     return false;
--- a/js/src/proxy/SecurityWrapper.cpp
+++ b/js/src/proxy/SecurityWrapper.cpp
@@ -64,25 +64,25 @@ template <class Base>
 bool
 SecurityWrapper<Base>::isExtensible(JSContext *cx, HandleObject wrapper, bool *extensible) const
 {
     // See above.
     *extensible = true;
     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 <class Base>
 bool
 SecurityWrapper<Base>::defaultValue(JSContext *cx, HandleObject wrapper,
                                     JSType hint, MutableHandleValue vp) const
 {
-    return DefaultValue(cx, wrapper, hint, vp);
+    return OrdinaryToPrimitive(cx, wrapper, hint, vp);
 }
 
 template <class Base>
 bool
 SecurityWrapper<Base>::objectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx) const
 {
     return false;
 }
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -354,17 +354,17 @@ sandbox_moved(JSObject *obj, const JSObj
 static bool
 sandbox_convert(JSContext *cx, HandleObject obj, JSType type, MutableHandleValue vp)
 {
     if (type == JSTYPE_OBJECT) {
         vp.set(OBJECT_TO_JSVAL(obj));
         return true;
     }
 
-    return JS::OrdinaryToPrimitive(cx, obj, type, vp);
+    return OrdinaryToPrimitive(cx, obj, type, vp);
 }
 
 static bool
 writeToProto_setProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
                     bool strict, JS::MutableHandleValue vp)
 {
     RootedObject proto(cx);
     if (!JS_GetPrototype(cx, obj, &proto))
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -2145,21 +2145,21 @@ XrayWrapper<Base, Traits>::className(JSC
 }
 
 template <typename Base, typename Traits>
 bool
 XrayWrapper<Base, Traits>::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 <typename Base, typename Traits>
 bool
 XrayWrapper<Base, Traits>::getPrototypeOf(JSContext *cx, JS::HandleObject wrapper,
                                           JS::MutableHandleObject protop) const
 {
     // We really only want this override for non-SecurityWrapper-inheriting