summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/DOM/Document.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-04 22:12:37 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-04 22:12:37 +0200
commit9b0bfcb8b75fa9bae0061af0cf229ccd1aacb21c (patch)
tree09523e8d08a283a719d788aead828a84df6721ee /Libraries/LibWeb/DOM/Document.cpp
parent5e40aa182b9507559f20d94902a2ae868afe7393 (diff)
downloadserenity-9b0bfcb8b75fa9bae0061af0cf229ccd1aacb21c.zip
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()".
Diffstat (limited to 'Libraries/LibWeb/DOM/Document.cpp')
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 430d51590e..79b6d72cb8 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -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);
+}
+
}