mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +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:
parent
23b07b3408
commit
fbf9cb3387
Notes:
sideshowbarker
2024-07-17 07:14:09 +09:00
Author: https://github.com/awesomekling
Commit: fbf9cb3387
Pull-request: https://github.com/SerenityOS/serenity/pull/16398
Reviewed-by: https://github.com/linusg ✅
12 changed files with 187 additions and 292 deletions
|
@ -71,7 +71,7 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(DeprecatedString filename,
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/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)
|
||||
{
|
||||
auto& vm = settings_object().realm().vm();
|
||||
|
||||
|
@ -97,7 +97,7 @@ JS::Completion ClassicScript::run(RethrowErrors rethrow_errors)
|
|||
// 6. Otherwise, set evaluationStatus to ScriptEvaluation(script's record).
|
||||
auto interpreter = JS::Interpreter::create_with_existing_realm(m_script_record->realm());
|
||||
|
||||
evaluation_status = interpreter->run(*m_script_record);
|
||||
evaluation_status = 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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue