mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 06:37:52 +00:00
WebContent+LibWeb+LibJS: Simplify injection of JS console globals
Instead of creating a new global object and proxying everything through it, we now evaluate console inputs inside a `with` environment. This seems to match the behavior of WebKit and Gecko in my basic testing, and removes the ConsoleGlobalObject which has been a source of confusion and invalid downcasts. The globals now live in a class called ConsoleGlobalObjectExtensions (renamed from ConsoleGlobalObject since it's no longer a global object). To make this possible, I had to add a way to override the initial lexical environment when calling JS::Interpreter::run(). This is plumbed via Web::HTML::ClassicScript::run().
This commit is contained in:
committed by
Linus Groh
parent
23b07b3408
commit
fbf9cb3387
@@ -35,7 +35,7 @@ Interpreter::Interpreter(VM& vm)
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
@@ -62,6 +62,10 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record)
|
||||
// 7. Set the LexicalEnvironment of scriptContext to globalEnv.
|
||||
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.
|
||||
|
||||
// NOTE: This isn't in the spec, but we require it.
|
||||
|
||||
Reference in New Issue
Block a user