1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 20:55:07 +00:00

LibWeb: Handle javascript: URLs inside LibWeb :^)

This patch makes it possible to execute JavaScript by clicking on an
anchor element with href="javascript:your_script_here()".
This commit is contained in:
Andreas Kling 2020-04-04 22:12:37 +02:00
parent 5e40aa182b
commit 9b0bfcb8b7
4 changed files with 31 additions and 2 deletions

View file

@ -31,6 +31,7 @@
#include <LibGUI/DisplayLink.h>
#include <LibGUI/MessageBox.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/Function.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibWeb/Bindings/DocumentWrapper.h>
@ -365,4 +366,12 @@ JS::Interpreter& Document::interpreter()
return *m_interpreter;
}
JS::Value Document::run_javascript(const StringView& source)
{
auto program = JS::Parser(JS::Lexer(source)).parse_program();
dbg() << "Document::run_javascript('" << source << "') will run:";
program->dump(0);
return document().interpreter().run(*program);
}
}