diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-11 00:30:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-11 00:36:37 +0200 |
commit | 1484980f8fab5c24837844d773acf80cb8c4ad2a (patch) | |
tree | 6eba3faa3d1a322b3f6181cf0cb7b4ea5438e3bd /Userland/Libraries/LibWeb/HTML/Scripting | |
parent | 6595db9ecf0ca0e92e77281fb20dae1f99bc6619 (diff) | |
download | serenity-1484980f8fab5c24837844d773acf80cb8c4ad2a.zip |
LibWeb+LibJS: Remember source filenames when using HTML::Script
It's a lot easier to debug JavaScript problems if you can see which file
the errors are in. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/Scripting')
4 files changed, 12 insertions, 9 deletions
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; }; } |