Bug 1140670 part 2. Just use the global as the parent in js::CreateThis and js::CreateThisForFunctionWithProto. r=waldo
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 09 Mar 2015 12:50:56 -0400
changeset 249262 7860e3827f62bb4f831f1ceb80a7143e9ef45cb5
parent 249261 7e52fd8d932467657b412e304a03a7e179423eb5
child 249263 6f69dbcdd73a437286f7ae77f125ef8d25b41135
push id971
push userjbruaroey@mozilla.com
push dateTue, 10 Mar 2015 17:33:09 +0000
reviewerswaldo
bugs1140670
milestone39.0a1
Bug 1140670 part 2. Just use the global as the parent in js::CreateThis and js::CreateThisForFunctionWithProto. r=waldo
js/src/jsobj.cpp
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -1505,23 +1505,22 @@ js::NewObjectScriptedCall(JSContext *cx,
 JSObject*
 js::CreateThis(JSContext *cx, const Class *newclasp, HandleObject callee)
 {
     RootedValue protov(cx);
     if (!GetProperty(cx, callee, callee, cx->names().prototype, &protov))
         return nullptr;
 
     RootedObject proto(cx, protov.isObjectOrNull() ? protov.toObjectOrNull() : nullptr);
-    RootedObject parent(cx, callee->getParent());
     gc::AllocKind kind = NewObjectGCKind(newclasp);
-    return NewObjectWithClassProto(cx, newclasp, proto, parent, kind);
+    return NewObjectWithClassProto(cx, newclasp, proto, NullPtr(), kind);
 }
 
 static inline JSObject *
-CreateThisForFunctionWithGroup(JSContext *cx, HandleObjectGroup group, HandleObject parent,
+CreateThisForFunctionWithGroup(JSContext *cx, HandleObjectGroup group,
                                NewObjectKind newKind)
 {
     if (group->maybeUnboxedLayout() && newKind != SingletonObject)
         return UnboxedPlainObject::create(cx, group, newKind);
 
     if (TypeNewScript *newScript = group->newScript()) {
         if (newScript->analyzed()) {
             // The definite properties analysis has been performed for this
@@ -1548,35 +1547,34 @@ CreateThisForFunctionWithGroup(JSContext
         // nursery.
         if (newKind == GenericObject)
             newKind = MaybeSingletonObject;
 
         // Not enough objects with this group have been created yet, so make a
         // plain object and register it with the group. Use the maximum number
         // of fixed slots, as is also required by the TypeNewScript.
         gc::AllocKind allocKind = GuessObjectGCKind(NativeObject::MAX_FIXED_SLOTS);
-        PlainObject *res = NewObjectWithGroup<PlainObject>(cx, group, parent, allocKind, newKind);
+        PlainObject *res = NewObjectWithGroup<PlainObject>(cx, group, cx->global(), allocKind, newKind);
         if (!res)
             return nullptr;
 
         if (newKind != SingletonObject)
             newScript->registerNewObject(res);
 
         return res;
     }
 
     gc::AllocKind allocKind = NewObjectGCKind(&PlainObject::class_);
 
     if (newKind == SingletonObject) {
         Rooted<TaggedProto> protoRoot(cx, group->proto());
-        RootedObject parentRoot(cx, parent);
-        return NewObjectWithGivenTaggedProto(cx, &PlainObject::class_, protoRoot, parentRoot,
+        return NewObjectWithGivenTaggedProto(cx, &PlainObject::class_, protoRoot, cx->global(),
                                              allocKind, newKind);
     }
-    return NewObjectWithGroup<PlainObject>(cx, group, parent, allocKind, newKind);
+    return NewObjectWithGroup<PlainObject>(cx, group, cx->global(), allocKind, newKind);
 }
 
 JSObject *
 js::CreateThisForFunctionWithProto(JSContext *cx, HandleObject callee, HandleObject proto,
                                    NewObjectKind newKind /* = GenericObject */)
 {
     RootedObject res(cx);
 
@@ -1594,22 +1592,21 @@ js::CreateThisForFunctionWithProto(JSCon
                 // The script was analyzed successfully and may have changed
                 // the new type table, so refetch the group.
                 group = ObjectGroup::defaultNewGroup(cx, nullptr, TaggedProto(proto),
                                                      &callee->as<JSFunction>());
                 MOZ_ASSERT(group && group->newScript());
             }
         }
 
-        RootedObject parent(cx, callee->getParent());
-        res = CreateThisForFunctionWithGroup(cx, group, parent, newKind);
+        res = CreateThisForFunctionWithGroup(cx, group, newKind);
     } else {
-        RootedObject parent(cx, callee->getParent());
         gc::AllocKind allocKind = NewObjectGCKind(&PlainObject::class_);
-        res = NewObjectWithProto<PlainObject>(cx, proto, parent, allocKind, newKind);
+        res = NewObjectWithProto<PlainObject>(cx, proto, cx->global(),
+                                              allocKind, newKind);
     }
 
     if (res) {
         JSScript *script = callee->as<JSFunction>().getOrCreateScript(cx);
         if (!script)
             return nullptr;
         TypeScript::SetThis(cx, script, TypeSet::ObjectType(res));
     }