Browse Source

Revert "LibJS+LibWeb: Remove now-unused lexical environment override"

This reverts commit d39f6975f9c8209d422734b830ad22196a54b79d.
Timothy Flynn 8 months ago
parent
commit
d40b7d67b1

+ 5 - 1
Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

@@ -182,7 +182,7 @@ ALWAYS_INLINE Value Interpreter::do_yield(Value value, Optional<Label> continuat
 }
 }
 
 
 // 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
 // 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
-ThrowCompletionOr<Value> Interpreter::run(Script& script_record)
+ThrowCompletionOr<Value> Interpreter::run(Script& script_record, JS::GCPtr<Environment> lexical_environment_override)
 {
 {
     auto& vm = this->vm();
     auto& vm = this->vm();
 
 
@@ -207,6 +207,10 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record)
     // 7. Set the LexicalEnvironment of scriptContext to globalEnv.
     // 7. Set the LexicalEnvironment of scriptContext to globalEnv.
     script_context->lexical_environment = &global_environment;
     script_context->lexical_environment = &global_environment;
 
 
+    // Non-standard: Override the lexical environment if requested.
+    if (lexical_environment_override)
+        script_context->lexical_environment = lexical_environment_override;
+
     // 8. Set the PrivateEnvironment of scriptContext to null.
     // 8. Set the PrivateEnvironment of scriptContext to null.
 
 
     // NOTE: This isn't in the spec, but we require it.
     // NOTE: This isn't in the spec, but we require it.

+ 1 - 1
Userland/Libraries/LibJS/Bytecode/Interpreter.h

@@ -30,7 +30,7 @@ public:
     VM& vm() { return m_vm; }
     VM& vm() { return m_vm; }
     VM const& vm() const { return m_vm; }
     VM const& vm() const { return m_vm; }
 
 
-    ThrowCompletionOr<Value> run(Script&);
+    ThrowCompletionOr<Value> run(Script&, JS::GCPtr<Environment> lexical_environment_override = nullptr);
     ThrowCompletionOr<Value> run(SourceTextModule&);
     ThrowCompletionOr<Value> run(SourceTextModule&);
 
 
     ThrowCompletionOr<Value> run(Bytecode::Executable& executable, Optional<size_t> entry_point = {}, Value initial_accumulator_value = {})
     ThrowCompletionOr<Value> run(Bytecode::Executable& executable, Optional<size_t> entry_point = {}, Value initial_accumulator_value = {})

+ 2 - 2
Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp

@@ -75,7 +75,7 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, Strin
 
 
 // https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
 // https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
 // https://whatpr.org/html/9893/webappapis.html#run-a-classic-script
 // https://whatpr.org/html/9893/webappapis.html#run-a-classic-script
-JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
+JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, JS::GCPtr<JS::Environment> lexical_environment_override)
 {
 {
     // 1. Let realm be the realm of script.
     // 1. Let realm be the realm of script.
     auto& realm = this->realm();
     auto& realm = this->realm();
@@ -97,7 +97,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
         auto timer = Core::ElapsedTimer::start_new();
         auto timer = Core::ElapsedTimer::start_new();
 
 
         // 6. Otherwise, set evaluationStatus to ScriptEvaluation(script's record).
         // 6. Otherwise, set evaluationStatus to ScriptEvaluation(script's record).
-        evaluation_status = vm().bytecode_interpreter().run(*m_script_record);
+        evaluation_status = vm().bytecode_interpreter().run(*m_script_record, lexical_environment_override);
 
 
         // FIXME: If ScriptEvaluation does not complete because the user agent has aborted the running script, leave evaluationStatus as null.
         // FIXME: If ScriptEvaluation does not complete because the user agent has aborted the running script, leave evaluationStatus as null.
 
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h

@@ -33,7 +33,7 @@ public:
         No,
         No,
         Yes,
         Yes,
     };
     };
-    JS::Completion run(RethrowErrors = RethrowErrors::No);
+    JS::Completion run(RethrowErrors = RethrowErrors::No, JS::GCPtr<JS::Environment> lexical_environment_override = {});
 
 
     MutedErrors muted_errors() const { return m_muted_errors; }
     MutedErrors muted_errors() const { return m_muted_errors; }