mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
LibWeb: Provide file name to JavaScript interpreter
This commit is contained in:
parent
6172cb3599
commit
8dca96fb61
4 changed files with 7 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -72,6 +72,7 @@ private:
|
|||
Function<void()> m_script_ready_callback;
|
||||
|
||||
String m_script_source;
|
||||
String m_script_filename;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue