Skip to content

Commit

Permalink
LibWeb: Provide file name to JavaScript interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
boricj authored and awesomekling committed Mar 1, 2021
1 parent 6172cb3 commit 8dca96f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/DOM/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Document

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);
Expand Down
4 changes: 3 additions & 1 deletion Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Web::HTML {

HTMLScriptElement::HTMLScriptElement(DOM::Document& document, QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
, m_script_filename("(document)")
{
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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&) {
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class HTMLScriptElement final : public HTMLElement {
Function<void()> m_script_ready_callback;

String m_script_source;
String m_script_filename;
};

}

0 comments on commit 8dca96f

Please sign in to comment.