Bug 1397385 - Simplify js::GetThisValue
Remaining uses should only require it to outerize globals and perform
sanity checks.
MozReview-Commit-ID: JGq3gp3tAbY
--- 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));