Bug 1111248. r=Waldo, a=sledru
authorTom Schuster <evilpies@gmail.com>
Mon, 26 Jan 2015 10:57:14 -0500
changeset 243040 7f44816c0449
parent 243039 a532a2852b2f
child 243041 bf8644a5c52a
push id4370
push userryanvm@gmail.com
push date2015-01-26 15:57 +0000
treeherdermozilla-beta@bf8644a5c52a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo, sledru
bugs1111248
milestone36.0
Bug 1111248. r=Waldo, a=sledru
js/src/jsbool.cpp
js/src/jsbool.h
js/src/jsboolinlines.h
js/src/json.cpp
--- a/js/src/jsbool.cpp
+++ b/js/src/jsbool.cpp
@@ -107,16 +107,17 @@ bool_valueOf(JSContext *cx, unsigned arg
     return CallNonGenericMethod<IsBoolean, bool_valueOf_impl>(cx, args);
 }
 
 static const JSFunctionSpec boolean_methods[] = {
 #if JS_HAS_TOSOURCE
     JS_FN(js_toSource_str,  bool_toSource,  0, 0),
 #endif
     JS_FN(js_toString_str,  bool_toString,  0, 0),
+    JS_FN(js_valueOf_str,   bool_valueOf,   0, 0),
     JS_FS_END
 };
 
 static bool
 Boolean(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
@@ -150,30 +151,16 @@ js_InitBooleanClass(JSContext *cx, Handl
         return nullptr;
 
     if (!LinkConstructorAndPrototype(cx, ctor, booleanProto))
         return nullptr;
 
     if (!DefinePropertiesAndFunctions(cx, booleanProto, nullptr, boolean_methods))
         return nullptr;
 
-    Handle<PropertyName*> valueOfName = cx->names().valueOf;
-    RootedFunction
-        valueOf(cx, NewFunction(cx, NullPtr(), bool_valueOf, 0, JSFunction::NATIVE_FUN,
-                                global, valueOfName));
-    if (!valueOf)
-        return nullptr;
-
-    RootedValue value(cx, ObjectValue(*valueOf));
-    if (!JSObject::defineProperty(cx, booleanProto, valueOfName, value,
-                                  JS_PropertyStub, JS_StrictPropertyStub, 0))
-    {
-        return nullptr;
-    }
-
     if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_Boolean, ctor, booleanProto))
         return nullptr;
 
     return booleanProto;
 }
 
 JSString *
 js_BooleanToString(ExclusiveContext *cx, bool b)
@@ -185,20 +172,8 @@ JS_PUBLIC_API(bool)
 js::ToBooleanSlow(HandleValue v)
 {
     if (v.isString())
         return v.toString()->length() != 0;
 
     MOZ_ASSERT(v.isObject());
     return !EmulatesUndefined(&v.toObject());
 }
-
-/*
- * This slow path is only ever taken for proxies wrapping Boolean objects
- * The only caller of the fast path, JSON's PreprocessValue, ensures that.
- */
-bool
-js::BooleanGetPrimitiveValueSlow(HandleObject wrappedBool)
-{
-    JSObject *obj = wrappedBool->as<ProxyObject>().target();
-    MOZ_ASSERT(obj);
-    return obj->as<BooleanObject>().unbox();
-}
--- a/js/src/jsbool.h
+++ b/js/src/jsbool.h
@@ -14,16 +14,9 @@
 #include "NamespaceImports.h"
 
 extern JSObject *
 js_InitBooleanClass(JSContext *cx, js::HandleObject obj);
 
 extern JSString *
 js_BooleanToString(js::ExclusiveContext *cx, bool b);
 
-namespace js {
-
-inline bool
-BooleanGetPrimitiveValue(HandleObject obj);
-
-} /* namespace js */
-
 #endif /* jsbool_h */
--- a/js/src/jsboolinlines.h
+++ b/js/src/jsboolinlines.h
@@ -9,28 +9,16 @@
 
 #include "jsbool.h"
 
 #include "vm/BooleanObject.h"
 #include "vm/WrapperObject.h"
 
 namespace js {
 
-bool
-BooleanGetPrimitiveValueSlow(HandleObject);
-
-inline bool
-BooleanGetPrimitiveValue(HandleObject obj)
-{
-    if (obj->is<BooleanObject>())
-        return obj->as<BooleanObject>().unbox();
-
-    return BooleanGetPrimitiveValueSlow(obj);
-}
-
 inline bool
 EmulatesUndefined(JSObject *obj)
 {
     JSObject *actual = MOZ_LIKELY(!obj->is<WrapperObject>()) ? obj : UncheckedUnwrap(obj);
     return actual->getClass()->emulatesUndefined();
 }
 
 } /* namespace js */
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -265,24 +265,25 @@ PreprocessValue(JSContext *cx, HandleObj
 
     /* Step 4. */
     if (vp.get().isObject()) {
         RootedObject obj(cx, &vp.get().toObject());
         if (ObjectClassIs(obj, ESClass_Number, cx)) {
             double d;
             if (!ToNumber(cx, vp, &d))
                 return false;
-            vp.set(NumberValue(d));
+            vp.setNumber(d);
         } else if (ObjectClassIs(obj, ESClass_String, cx)) {
             JSString *str = ToStringSlow<CanGC>(cx, vp);
             if (!str)
                 return false;
-            vp.set(StringValue(str));
+            vp.setString(str);
         } else if (ObjectClassIs(obj, ESClass_Boolean, cx)) {
-            vp.setBoolean(BooleanGetPrimitiveValue(obj));
+            if (!Unbox(cx, obj, vp))
+                return false;
         }
     }
 
     return true;
 }
 
 /*
  * Determines whether a value which has passed by ES5 150.2.3 Str steps 1-4's
@@ -897,26 +898,20 @@ static const JSFunctionSpec json_static_
     JS_FS_END
 };
 
 JSObject *
 js_InitJSONClass(JSContext *cx, HandleObject obj)
 {
     Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
 
-    /*
-     * JSON requires that Boolean.prototype.valueOf be created and stashed in a
-     * reserved slot on the global object; see js::BooleanGetPrimitiveValueSlow
-     * called from PreprocessValue above.
-     */
-    if (!GlobalObject::getOrCreateBooleanPrototype(cx, global))
+    RootedObject proto(cx, global->getOrCreateObjectPrototype(cx));
+    if (!proto)
         return nullptr;
-
-    RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
-    RootedObject JSON(cx, NewObjectWithClassProto(cx, &JSONClass, proto, global, SingletonObject));
+    RootedObject JSON(cx, NewObjectWithGivenProto(cx, &JSONClass, proto, global, SingletonObject));
     if (!JSON)
         return nullptr;
 
     if (!JS_DefineProperty(cx, global, js_JSON_str, JSON, 0,
                            JS_STUBGETTER, JS_STUBSETTER))
         return nullptr;
 
     if (!JS_DefineFunctions(cx, JSON, json_static_methods))