Bug 942211 - Remove usages of NewObjectWithClassProto. r=jwalden
authorTill Schneidereit <till@tillschneidereit.net>
Mon, 25 Nov 2013 11:40:53 +0000
changeset 172978 e4c2a0b98917fe243b8b8594378cf59e17d1ec78
parent 172977 324d93c55cc5c43aa74056c9e89a5ebc60916105
child 172979 dc27d67ceda76ab6d39472544a44eb1196559066
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs942211
milestone28.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 942211 - Remove usages of NewObjectWithClassProto. r=jwalden
js/src/builtin/TypedObject.cpp
js/src/jsmath.cpp
js/src/json.cpp
js/src/jsreflect.cpp
js/src/vm/GlobalObject.cpp
--- a/js/src/builtin/TypedObject.cpp
+++ b/js/src/builtin/TypedObject.cpp
@@ -867,17 +867,17 @@ ArrayType::create(JSContext *cx,
                                cx->names().prototype,
                                &prototypeVal))
     {
         return nullptr;
     }
     JS_ASSERT(prototypeVal.isObject()); // immutable binding
 
     RootedObject obj(
-        cx, NewObjectWithClassProto(cx, &ArrayType::class_,
+        cx, NewObjectWithGivenProto(cx, &ArrayType::class_,
                                     &prototypeVal.toObject(), cx->global()));
     if (!obj)
         return nullptr;
     obj->initReservedSlot(JS_TYPEOBJ_SLOT_TYPE_REPR, ObjectValue(*typeReprObj));
 
     RootedValue elementTypeVal(cx, ObjectValue(*elementType));
     if (!JSObject::defineProperty(cx, obj, cx->names().elementType,
                                   elementTypeVal, nullptr, nullptr,
@@ -1140,17 +1140,17 @@ StructType::create(JSContext *cx, Handle
     RootedValue prototypeVal(cx);
     if (!JSObject::getProperty(cx, metaTypeObject, metaTypeObject,
                                cx->names().prototype,
                                &prototypeVal))
         return nullptr;
     JS_ASSERT(prototypeVal.isObject()); // immutable binding
 
     RootedObject obj(
-        cx, NewObjectWithClassProto(cx, &StructType::class_,
+        cx, NewObjectWithGivenProto(cx, &StructType::class_,
                                     &prototypeVal.toObject(), cx->global()));
     if (!obj)
         return nullptr;
 
     if (!StructType::layout(cx, obj, fields))
         return nullptr;
 
     RootedObject fieldsProto(cx);
@@ -1244,25 +1244,25 @@ StructType::construct(JSContext *cx, uns
  *        StructType.prototype.prototype -__proto__->
  *          Objcet.prototype
  */
 
 // Here `T` is either `ScalarType` or `ReferenceType`
 template<typename T>
 static bool
 DefineSimpleTypeObject(JSContext *cx,
-                       HandleObject global,
+                       Handle<GlobalObject *> global,
                        HandleObject module,
                        typename T::TypeRepr::Type type,
                        HandlePropertyName className)
 {
-    RootedObject funcProto(cx, JS_GetFunctionPrototype(cx, global));
+    RootedObject funcProto(cx, global->getOrCreateFunctionPrototype(cx));
     JS_ASSERT(funcProto);
 
-    RootedObject numFun(cx, NewObjectWithClassProto(cx, &T::class_, funcProto, global));
+    RootedObject numFun(cx, NewObjectWithGivenProto(cx, &T::class_, funcProto, global));
     if (!numFun)
         return false;
 
     RootedObject typeReprObj(cx, T::TypeRepr::Create(cx, type));
     if (!typeReprObj)
         return false;
 
     numFun->initReservedSlot(JS_TYPEOBJ_SLOT_TYPE_REPR,
@@ -1516,17 +1516,17 @@ js_InitTypedObjectClass(JSContext *cx, H
 
     JS_ASSERT(obj->is<GlobalObject>());
     Rooted<GlobalObject *> global(cx, &obj->as<GlobalObject>());
 
     RootedObject objProto(cx, global->getOrCreateObjectPrototype(cx));
     if (!objProto)
         return nullptr;
 
-    RootedObject module(cx, NewObjectWithClassProto(cx, &JSObject::class_,
+    RootedObject module(cx, NewObjectWithGivenProto(cx, &JSObject::class_,
                                                     objProto, global));
     if (!module)
         return nullptr;
 
     if (!JS_DefineFunctions(cx, module, TypedObjectMethods))
         return nullptr;
 
     // Define TypedObject global.
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -1470,17 +1470,20 @@ static const JSFunctionSpec math_static_
     JS_FN("sign",           math_sign,            1, 0),
     JS_FN("cbrt",           math_cbrt,            1, 0),
     JS_FS_END
 };
 
 JSObject *
 js_InitMathClass(JSContext *cx, HandleObject obj)
 {
-    RootedObject Math(cx, NewObjectWithClassProto(cx, &MathClass, nullptr, obj, SingletonObject));
+    RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
+    if (!proto)
+        return nullptr;
+    RootedObject Math(cx, NewObjectWithGivenProto(cx, &MathClass, proto, obj, SingletonObject));
     if (!Math)
         return nullptr;
 
     if (!JS_DefineProperty(cx, obj, js_Math_str, OBJECT_TO_JSVAL(Math),
                            JS_PropertyStub, JS_StrictPropertyStub, 0)) {
         return nullptr;
     }
 
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -868,18 +868,18 @@ js_InitJSONClass(JSContext *cx, HandleOb
     /*
      * 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 (!global->getOrCreateBooleanPrototype(cx))
         return nullptr;
 
-    RootedObject JSON(cx, NewObjectWithClassProto(cx, &JSONClass, nullptr,
-                                                  global, SingletonObject));
+    RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
+    RootedObject JSON(cx, NewObjectWithClassProto(cx, &JSONClass, proto, global, SingletonObject));
     if (!JSON)
         return nullptr;
 
     if (!JS_DefineProperty(cx, global, js_JSON_str, OBJECT_TO_JSVAL(JSON),
                            JS_PropertyStub, JS_StrictPropertyStub, 0))
         return nullptr;
 
     if (!JS_DefineFunctions(cx, JSON, json_static_methods))
--- a/js/src/jsreflect.cpp
+++ b/js/src/jsreflect.cpp
@@ -3308,17 +3308,20 @@ JS_PUBLIC_API(JSObject *)
 JS_InitReflect(JSContext *cx, JSObject *objArg)
 {
     static const JSFunctionSpec static_methods[] = {
         JS_FN("parse", reflect_parse, 1, 0),
         JS_FS_END
     };
 
     RootedObject obj(cx, objArg);
-    RootedObject Reflect(cx, NewObjectWithClassProto(cx, &JSObject::class_, nullptr,
+    RootedObject proto(cx, obj->as<GlobalObject>().getOrCreateObjectPrototype(cx));
+    if (!proto)
+        return nullptr;
+    RootedObject Reflect(cx, NewObjectWithGivenProto(cx, &JSObject::class_, proto,
                                                      obj, SingletonObject));
     if (!Reflect)
         return nullptr;
 
     if (!JS_DefineProperty(cx, obj, "Reflect", OBJECT_TO_JSVAL(Reflect),
                            JS_PropertyStub, JS_StrictPropertyStub, 0)) {
         return nullptr;
     }
--- a/js/src/vm/GlobalObject.cpp
+++ b/js/src/vm/GlobalObject.cpp
@@ -382,17 +382,21 @@ GlobalObject::initFunctionAndObjectClass
     if (!JSObject::preventExtensions(cx, throwTypeError))
         return nullptr;
     self->setThrowTypeError(throwTypeError);
 
     RootedObject intrinsicsHolder(cx);
     if (cx->runtime()->isSelfHostingGlobal(self)) {
         intrinsicsHolder = self;
     } else {
-        intrinsicsHolder = NewObjectWithClassProto(cx, &JSObject::class_, nullptr, self, TenuredObject);
+        RootedObject proto(cx, self->getOrCreateObjectPrototype(cx));
+        if (!proto)
+            return nullptr;
+        intrinsicsHolder = NewObjectWithGivenProto(cx, &JSObject::class_, proto, self,
+                                                   TenuredObject);
         if (!intrinsicsHolder)
             return nullptr;
     }
     self->setIntrinsicsHolder(intrinsicsHolder);
     /* Define a property 'global' with the current global as its value. */
     RootedValue global(cx, ObjectValue(*self));
     if (!JSObject::defineProperty(cx, intrinsicsHolder, cx->names().global,
                                   global, JS_PropertyStub, JS_StrictPropertyStub,