diff options
author | Jean-Baptiste Boric <jblbeurope@gmail.com> | 2021-02-27 19:35:45 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-01 11:14:36 +0100 |
commit | 8dca96fb61f2594adbecf4b477d36533bf5f7e37 (patch) | |
tree | bb0f1f204a6b2464058a3592c15380371653b4a7 /Userland | |
parent | 6172cb35994718651f91e79a53bbd792f29846b9 (diff) | |
download | serenity-8dca96fb61f2594adbecf4b477d36533bf5f7e37.zip |
LibWeb: Provide file name to JavaScript interpreter
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h | 1 |
4 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 242b2924b8..7e6592330b 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -546,9 +546,9 @@ JS::Interpreter& Document::interpreter() return *m_interpreter; } -JS::Value Document::run_javascript(const StringView& source) +JS::Value Document::run_javascript(const StringView& source, const StringView& filename) { - auto parser = JS::Parser(JS::Lexer(source)); + auto parser = JS::Parser(JS::Lexer(source, filename)); auto program = parser.parse_program(); if (parser.has_errors()) { parser.print_errors(); diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 30c4c17b32..b124965d9e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -157,7 +157,7 @@ public: virtual JS::Interpreter& interpreter() override; - JS::Value run_javascript(const StringView&); + JS::Value run_javascript(const StringView& source, const StringView& filename = "(unknown)"); NonnullRefPtr<Element> create_element(const String& tag_name); NonnullRefPtr<Element> create_element_ns(const String& namespace_, const String& qualifed_name); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index e3a64bcbb9..2498d5f167 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -40,6 +40,7 @@ namespace Web::HTML { HTMLScriptElement::HTMLScriptElement(DOM::Document& document, QualifiedName qualified_name) : HTMLElement(document, move(qualified_name)) + , m_script_filename("(document)") { } @@ -89,7 +90,7 @@ void HTMLScriptElement::execute_script() else dbgln_if(HTML_SCRIPT_DEBUG, "HTMLScriptElement: Running inline script"); - document().run_javascript(m_script_source); + document().run_javascript(m_script_source, m_script_filename); document().set_current_script({}, old_current_script); } else { @@ -229,6 +230,7 @@ void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>) if (m_script_type == ScriptType::Classic) { // FIXME: This load should be made asynchronous and the parser should spin an event loop etc. + m_script_filename = url.basename(); ResourceLoader::the().load_sync( url, [this, url](auto data, auto&) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h index 194fd4143a..88b55c3bcc 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h @@ -72,6 +72,7 @@ private: Function<void()> m_script_ready_callback; String m_script_source; + String m_script_filename; }; } |