mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
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. :^)
This commit is contained in:
parent
6595db9ecf
commit
1484980f8f
7 changed files with 17 additions and 14 deletions
|
@ -12,10 +12,10 @@
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
// 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script
|
// 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).
|
// 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.
|
// FIXME: 2. If body is a List of errors, return body.
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace JS {
|
||||||
class Script : public RefCounted<Script> {
|
class Script : public RefCounted<Script> {
|
||||||
public:
|
public:
|
||||||
~Script();
|
~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(); }
|
GlobalObject& global_object() { return *m_global_object.cell(); }
|
||||||
Program const& parse_node() const { return *m_parse_node; }
|
Program const& parse_node() const { return *m_parse_node; }
|
||||||
|
|
|
@ -303,7 +303,7 @@ void HTMLScriptElement::prepare_script()
|
||||||
document().interpreter();
|
document().interpreter();
|
||||||
|
|
||||||
// FIXME: This is all ad-hoc and needs work.
|
// 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.
|
// When the chosen algorithm asynchronously completes, set the script's script to the result. At that time, the script is ready.
|
||||||
m_script = script;
|
m_script = script;
|
||||||
|
@ -330,7 +330,7 @@ void HTMLScriptElement::prepare_script()
|
||||||
document().interpreter();
|
document().interpreter();
|
||||||
|
|
||||||
// FIXME: Pass settings, base URL and options.
|
// 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.
|
// 2. Set the script's script to script.
|
||||||
m_script = script;
|
m_script = script;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script
|
// 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.)
|
// 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.
|
// 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.
|
// 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.
|
// 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.
|
// FIXME: 9. Set script's parse error and error to rethrow to null.
|
||||||
|
|
||||||
// 10. Let result be ParseScript(source, settings's Realm, script).
|
// 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:
|
// FIXME: 11. If result is a list of errors, then:
|
||||||
// 1. Set script's parse error and its error to rethrow to result[0].
|
// 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();
|
return vm.last_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassicScript::ClassicScript(URL base_url)
|
ClassicScript::ClassicScript(URL base_url, String filename)
|
||||||
: Script(move(base_url))
|
: Script(move(base_url), move(filename))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
No,
|
No,
|
||||||
Yes,
|
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* script_record() { return m_script_record; }
|
||||||
JS::Script const* script_record() const { 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);
|
JS::Value run(RethrowErrors = RethrowErrors::No);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ClassicScript(URL base_url);
|
ClassicScript(URL base_url, String filename);
|
||||||
|
|
||||||
RefPtr<JS::Script> m_script_record;
|
RefPtr<JS::Script> m_script_record;
|
||||||
MutedErrors m_muted_errors { MutedErrors::No };
|
MutedErrors m_muted_errors { MutedErrors::No };
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
Script::Script(URL base_url)
|
Script::Script(URL base_url, String filename)
|
||||||
: m_base_url(move(base_url))
|
: m_base_url(move(base_url))
|
||||||
|
, m_filename(move(filename))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,14 @@ public:
|
||||||
virtual ~Script();
|
virtual ~Script();
|
||||||
|
|
||||||
URL const& base_url() const { return m_base_url; }
|
URL const& base_url() const { return m_base_url; }
|
||||||
|
String const& filename() const { return m_filename; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Script(URL base_url);
|
Script(URL base_url, String filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
URL m_base_url;
|
URL m_base_url;
|
||||||
|
String m_filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue