Bug 577750 - Make computing global this a little simpler. r=jorendorff
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 15 Jul 2010 23:49:13 -0700
changeset 50472 4d411039d112b2e05736fccc6dca3a8ac698aace
parent 50471 cf9fc9bb9c3ef823cd09addad8e2c3f9262fef2d
child 50473 36c4d4e837bbc37fc4c8608cad4affccd1f2ddce
push idunknown
push userunknown
push dateunknown
reviewersjorendorff
bugs577750
milestone2.0b4pre
Bug 577750 - Make computing global this a little simpler. r=jorendorff
js/src/jsapi.cpp
js/src/jsinterp.cpp
js/src/shell/js.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2851,16 +2851,17 @@ JS_GetParent(JSContext *cx, JSObject *ob
     /* Beware ref to dead object (we may be called from obj's finalizer). */
     return parent && parent->map ? parent : NULL;
 }
 
 JS_PUBLIC_API(JSBool)
 JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent)
 {
     CHECK_REQUEST(cx);
+    JS_ASSERT(parent || !obj->getParent());
     assertSameCompartment(cx, obj, parent);
     obj->setParent(parent);
     return true;
 }
 
 JS_PUBLIC_API(JSObject *)
 JS_GetConstructor(JSContext *cx, JSObject *proto)
 {
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -263,46 +263,27 @@ CallThisObjectHook(JSContext *cx, JSObje
  *   alert(h() == w1)
  *
  * The alert should display "true".
  */
 JS_STATIC_INTERPRET JSObject *
 ComputeGlobalThis(JSContext *cx, Value *argv)
 {
     /* Find the inner global. */
-    JSObject *inner;
-    if (argv[-2].isPrimitive() || !argv[-2].toObject().getParent()) {
-        inner = cx->globalObject;
-        OBJ_TO_INNER_OBJECT(cx, inner);
-        if (!inner)
-            return NULL;
-    } else {
-        inner = argv[-2].toObject().getGlobal();
-    }
-    JS_ASSERT(inner->getClass()->flags & JSCLASS_IS_GLOBAL);
-
-    JSObject *scope = JS_GetGlobalForScopeChain(cx);
-    if (scope == inner) {
-        /*
-         * The outer object has not moved along to a new inner object.
-         * This means we qualify for the cache slot in the global.
-         */
-        const Value &thisv = inner->getReservedSlot(JSRESERVED_GLOBAL_THIS);
-        if (!thisv.isUndefined()) {
-            argv[-1] = thisv;
-            return thisv.toObjectOrNull();
-        }
-
-        JSObject *stuntThis = CallThisObjectHook(cx, inner, argv);
-        JS_ALWAYS_TRUE(js_SetReservedSlot(cx, inner, JSRESERVED_GLOBAL_THIS,
-                                          ObjectOrNullValue(stuntThis)));
-        return stuntThis;
-    }
-
-    return CallThisObjectHook(cx, inner, argv);
+    JSObject *global = argv[-2].toObject().getGlobal();
+    const Value &thisv = global->getReservedSlot(JSRESERVED_GLOBAL_THIS);
+    if (!thisv.isUndefined()) {
+        argv[-1] = thisv;
+        return thisv.toObjectOrNull();
+    }
+
+    JSObject *stuntThis = CallThisObjectHook(cx, global, argv);
+    JS_ALWAYS_TRUE(js_SetReservedSlot(cx, global, JSRESERVED_GLOBAL_THIS,
+                                      ObjectOrNullValue(stuntThis)));
+    return stuntThis;
 }
 
 namespace js {
 
 JSObject *
 ComputeThisFromArgv(JSContext *cx, Value *argv)
 {
     JS_ASSERT(!argv[-1].isMagic(JS_THIS_POISON));
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2877,17 +2877,17 @@ split_create_outer(JSContext *cx)
     if (!cpx)
         return NULL;
     cpx->isInner = JS_FALSE;
     cpx->frozen = JS_TRUE;
     cpx->inner = NULL;
     cpx->outer = NULL;
 
     obj = JS_NewGlobalObject(cx, Jsvalify(&split_global_class));
-    if (!obj || !JS_SetParent(cx, obj, NULL)) {
+    if (!obj) {
         JS_free(cx, cpx);
         return NULL;
     }
 
     if (!JS_SetPrivate(cx, obj, cpx)) {
         JS_free(cx, cpx);
         return NULL;
     }
@@ -2907,17 +2907,17 @@ split_create_inner(JSContext *cx, JSObje
     if (!cpx)
         return NULL;
     cpx->isInner = JS_TRUE;
     cpx->frozen = JS_FALSE;
     cpx->inner = NULL;
     cpx->outer = outer;
 
     obj = JS_NewGlobalObject(cx, Jsvalify(&split_global_class));
-    if (!obj || !JS_SetParent(cx, obj, NULL) || !JS_SetPrivate(cx, obj, cpx)) {
+    if (!obj || !JS_SetParent(cx, obj, NULL)) {
         JS_free(cx, cpx);
         return NULL;
     }
 
     outercpx = (ComplexObject *) JS_GetPrivate(cx, outer);
     outercpx->inner = obj;
     outercpx->frozen = JS_FALSE;