mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb: Clear exceptions in each Document::run_javascript() call
We don't want to carry over exceptions across multiple Document::run_javascript() calls as Interpreter::run() and every of its exception checks will get confused - in this case there would be an exception, but not because a certain action failed. Real-life example: <script>var a = {}; a.test()</script> <script>alert("It worked!")</script> The above HTML will invoke Document::run_javascript() twice, the first call will result in a TypeError, which is still stored during the second call. The interpreter will eventually call the following functions (in order) for the alert() invocation: - Identifier::execute() - Interpreter::get_variable() - Object::get() (on the global object) That last Object::get() call has an exception check which is triggered as we still carry around the exception from earlier - and eventually returns an empty value. Long story short, the second script will wrongly fail with "ReferenceError, 'alert' is not defined". Fixes #3091.
This commit is contained in:
parent
f8084cc083
commit
1d728af5c4
Notes:
sideshowbarker
2024-07-19 03:53:07 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/1d728af5c46 Pull-request: https://github.com/SerenityOS/serenity/pull/3092 Reviewed-by: https://github.com/awesomekling
1 changed files with 5 additions and 1 deletions
|
@ -436,7 +436,11 @@ JS::Value Document::run_javascript(const StringView& source)
|
|||
parser.print_errors();
|
||||
return JS::js_undefined();
|
||||
}
|
||||
return document().interpreter().run(document().interpreter().global_object(), *program);
|
||||
auto& interpreter = document().interpreter();
|
||||
auto result = interpreter.run(interpreter.global_object(), *program);
|
||||
if (interpreter.exception())
|
||||
interpreter.clear_exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Element> Document::create_element(const String& tag_name)
|
||||
|
|
Loading…
Add table
Reference in a new issue