Bug 1696046 - Factor out implementation of JS_ExtensibleLexicalEnvironment to a non-API static method with a more specific return type. r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D107009
This commit is contained in:
Jason Orendorff 2021-03-04 11:00:40 +00:00
Родитель 04adcfaa73
Коммит 3032719103
4 изменённых файлов: 21 добавлений и 12 удалений

Просмотреть файл

@ -472,10 +472,8 @@ JS_FRIEND_API bool JS::ExecuteInJSMEnvironment(JSContext* cx,
ObjectRealm::get(varEnv).getNonSyntacticLexicalEnvironment(varEnv));
MOZ_DIAGNOSTIC_ASSERT(scriptArg->noScriptRval());
Rooted<ExtensibleLexicalEnvironmentObject*> env(cx);
if (auto* envPtr = JS_ExtensibleLexicalEnvironment(varEnv)) {
env = &envPtr->as<ExtensibleLexicalEnvironmentObject>();
}
Rooted<ExtensibleLexicalEnvironmentObject*> env(
cx, ExtensibleLexicalEnvironmentObject::forVarEnvironment(varEnv));
// If the Gecko subscript loader specifies target objects, we need to add
// them to the environment. These are added after the NSVO environment.

Просмотреть файл

@ -1249,14 +1249,7 @@ extern JS_PUBLIC_API bool JS_HasExtensibleLexicalEnvironment(JSObject* obj) {
}
extern JS_PUBLIC_API JSObject* JS_ExtensibleLexicalEnvironment(JSObject* obj) {
JSObject* lexical = nullptr;
if (obj->is<GlobalObject>()) {
lexical = JS_GlobalLexicalEnvironment(obj);
} else {
lexical = ObjectRealm::get(obj).getNonSyntacticLexicalEnvironment(obj);
}
MOZ_ASSERT(lexical);
return lexical;
return ExtensibleLexicalEnvironmentObject::forVarEnvironment(obj);
}
JS_PUBLIC_API JSObject* JS::CurrentGlobalOrNull(JSContext* cx) {

Просмотреть файл

@ -1112,6 +1112,19 @@ JSObject* ExtensibleLexicalEnvironmentObject::thisObject() const {
return obj;
}
/* static */
ExtensibleLexicalEnvironmentObject*
ExtensibleLexicalEnvironmentObject::forVarEnvironment(JSObject* obj) {
ExtensibleLexicalEnvironmentObject* lexical = nullptr;
if (obj->is<GlobalObject>()) {
lexical = &obj->as<GlobalObject>().lexicalEnvironment();
} else {
lexical = ObjectRealm::get(obj).getNonSyntacticLexicalEnvironment(obj);
}
MOZ_ASSERT(lexical);
return lexical;
}
/* static */
GlobalLexicalEnvironmentObject* GlobalLexicalEnvironmentObject::create(
JSContext* cx, Handle<GlobalObject*> global) {

Просмотреть файл

@ -619,6 +619,11 @@ class ExtensibleLexicalEnvironmentObject : public LexicalEnvironmentObject {
public:
JSObject* thisObject() const;
// For a given global object or JSMEnvironment `obj`, return the associated
// global lexical or non-syntactic lexical environment, where top-level `let`
// bindings are added.
static ExtensibleLexicalEnvironmentObject* forVarEnvironment(JSObject* obj);
protected:
void initThisObject(JSObject* obj) {
MOZ_ASSERT(isGlobal() || !isSyntactic());