summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibJS/Script.cpp4
-rw-r--r--Userland/Libraries/LibJS/Script.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp10
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h4
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp3
-rw-r--r--Userland/Libraries/LibWeb/HTML/Scripting/Script.h4
7 files changed, 17 insertions, 14 deletions
diff --git a/Userland/Libraries/LibJS/Script.cpp b/Userland/Libraries/LibJS/Script.cpp
index 442d6d0e13..02bb7d46fb 100644
--- a/Userland/Libraries/LibJS/Script.cpp
+++ b/Userland/Libraries/LibJS/Script.cpp
@@ -12,10 +12,10 @@
namespace JS {
// 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script
-NonnullRefPtr<Script> Script::parse(StringView source_text, GlobalObject& global_object)
+NonnullRefPtr<Script> Script::parse(StringView source_text, GlobalObject& global_object, StringView filename)
{
// 1. Let body be ParseText(sourceText, Script).
- auto body = Parser(Lexer(source_text)).parse_program();
+ auto body = Parser(Lexer(source_text, filename)).parse_program();
// FIXME: 2. If body is a List of errors, return body.
diff --git a/Userland/Libraries/LibJS/Script.h b/Userland/Libraries/LibJS/Script.h
index 4e6aa7a1c3..b11914d0a8 100644
--- a/Userland/Libraries/LibJS/Script.h
+++ b/Userland/Libraries/LibJS/Script.h
@@ -18,7 +18,7 @@ namespace JS {
class Script : public RefCounted<Script> {
public:
~Script();
- static NonnullRefPtr<Script> parse(StringView source_text, GlobalObject&);
+ static NonnullRefPtr<Script> parse(StringView source_text, GlobalObject&, StringView filename = {});
GlobalObject& global_object() { return *m_global_object.cell(); }
Program const& parse_node() const { return *m_parse_node; }
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
index 95e2bbb8b0..6d352f8b1d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
@@ -303,7 +303,7 @@ void HTMLScriptElement::prepare_script()
document().interpreter();
// FIXME: This is all ad-hoc and needs work.
- auto script = ClassicScript::create(data, *document().window().wrapper(), URL());
+ auto script = ClassicScript::create(url.to_string(), data, *document().window().wrapper(), URL());
// When the chosen algorithm asynchronously completes, set the script's script to the result. At that time, the script is ready.
m_script = script;
@@ -330,7 +330,7 @@ void HTMLScriptElement::prepare_script()
document().interpreter();
// FIXME: Pass settings, base URL and options.
- auto script = ClassicScript::create(source_text, *document().window().wrapper(), URL());
+ auto script = ClassicScript::create(m_document->url().to_string(), source_text, *document().window().wrapper(), URL());
// 2. Set the script's script to script.
m_script = script;
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp
index 50d3a89567..7038fa1b9d 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.cpp
@@ -10,7 +10,7 @@
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script
-NonnullRefPtr<ClassicScript> ClassicScript::create(StringView source, JS::GlobalObject& global_object, URL base_url, MutedErrors muted_errors)
+NonnullRefPtr<ClassicScript> ClassicScript::create(String filename, StringView source, JS::GlobalObject& global_object, URL base_url, MutedErrors muted_errors)
{
// 1. If muted errors was not provided, let it be false. (NOTE: This is taken care of by the default argument.)
@@ -21,7 +21,7 @@ NonnullRefPtr<ClassicScript> ClassicScript::create(StringView source, JS::Global
// FIXME: 3. If scripting is disabled for settings, then set source to the empty string.
// 4. Let script be a new classic script that this algorithm will subsequently initialize.
- auto script = adopt_ref(*new ClassicScript(move(base_url)));
+ auto script = adopt_ref(*new ClassicScript(move(base_url), move(filename)));
// FIXME: 5. Set script's settings object to settings.
@@ -35,7 +35,7 @@ NonnullRefPtr<ClassicScript> ClassicScript::create(StringView source, JS::Global
// FIXME: 9. Set script's parse error and error to rethrow to null.
// 10. Let result be ParseScript(source, settings's Realm, script).
- auto result = JS::Script::parse(source, global_object);
+ auto result = JS::Script::parse(source, global_object, script->filename());
// FIXME: 11. If result is a list of errors, then:
// 1. Set script's parse error and its error to rethrow to result[0].
@@ -61,8 +61,8 @@ JS::Value ClassicScript::run(RethrowErrors rethrow_errors)
return vm.last_value();
}
-ClassicScript::ClassicScript(URL base_url)
- : Script(move(base_url))
+ClassicScript::ClassicScript(URL base_url, String filename)
+ : Script(move(base_url), move(filename))
{
}
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h
index 2642c00bca..f2c5330bca 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/ClassicScript.h
@@ -20,7 +20,7 @@ public:
No,
Yes,
};
- static NonnullRefPtr<ClassicScript> create(StringView source, JS::GlobalObject&, URL base_url, MutedErrors = MutedErrors::No);
+ static NonnullRefPtr<ClassicScript> create(String filename, StringView source, JS::GlobalObject&, URL base_url, MutedErrors = MutedErrors::No);
JS::Script* script_record() { return m_script_record; }
JS::Script const* script_record() const { return m_script_record; }
@@ -32,7 +32,7 @@ public:
JS::Value run(RethrowErrors = RethrowErrors::No);
private:
- explicit ClassicScript(URL base_url);
+ ClassicScript(URL base_url, String filename);
RefPtr<JS::Script> m_script_record;
MutedErrors m_muted_errors { MutedErrors::No };
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp
index afd528880f..d915e0b85a 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Script.cpp
@@ -8,8 +8,9 @@
namespace Web::HTML {
-Script::Script(URL base_url)
+Script::Script(URL base_url, String filename)
: m_base_url(move(base_url))
+ , m_filename(move(filename))
{
}
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Script.h b/Userland/Libraries/LibWeb/HTML/Scripting/Script.h
index 4781a621ad..10a189ccba 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Script.h
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Script.h
@@ -17,12 +17,14 @@ public:
virtual ~Script();
URL const& base_url() const { return m_base_url; }
+ String const& filename() const { return m_filename; }
protected:
- explicit Script(URL base_url);
+ Script(URL base_url, String filename);
private:
URL m_base_url;
+ String m_filename;
};
}