Bug 1397385 - Simplify js::GetThisValue draft
authorTed Campbell <tcampbell@mozilla.com>
Fri, 08 Sep 2017 00:29:08 -0400
changeset 661492 309022953108679a883bf5cc5ae2365334df96d6
parent 661491 eab21506d9dcc653c0fea1a5d09ae3d6b8f36181
child 730590 c0b429a6dac4be2654ab08a58935e5d764975d59
push id78779
push userbmo:tcampbell@mozilla.com
push dateFri, 08 Sep 2017 14:53:54 +0000
bugs1397385
milestone57.0a1
Bug 1397385 - Simplify js::GetThisValue Remaining uses should only require it to outerize globals and perform sanity checks. MozReview-Commit-ID: JGq3gp3tAbY
js/src/jsobj.cpp
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -3251,28 +3251,24 @@ js::ToObjectSlow(JSContext* cx, JS::Hand
     }
 
     return PrimitiveToObject(cx, val);
 }
 
 Value
 js::GetThisValue(JSObject* obj)
 {
+    // Use the WindowProxy if the global is a Window, as Window must never be
+    // exposed to script.
     if (obj->is<GlobalObject>())
         return ObjectValue(*ToWindowProxyIfWindow(obj));
 
-    if (obj->is<LexicalEnvironmentObject>()) {
-        MOZ_ASSERT(!obj->as<LexicalEnvironmentObject>().isExtensible());
-        return UndefinedValue();
-    }
-
-    if (obj->is<ModuleEnvironmentObject>())
-        return UndefinedValue();
-
-    MOZ_ASSERT(!obj->is<WithEnvironmentObject>());
+    // We should not expose any environments except NSVOs to script. The NSVO is
+    // pretending to be the global object in this case.
+    MOZ_ASSERT(obj->is<NonSyntacticVariablesObject>() || !obj->is<EnvironmentObject>());
 
     return ObjectValue(*obj);
 }
 
 Value
 js::GetThisValueOfLexical(JSObject* env)
 {
     MOZ_ASSERT(IsExtensibleLexicalEnvironment(env));