mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibJS: Let JS::Script remember whether its code is strict mode
We don't want to rely on having the AST node just to answer the question "is this script strict mode?"
This commit is contained in:
parent
b712caf855
commit
892c7d980e
Notes:
github-actions[bot]
2025-10-27 20:15:42 +00:00
Author: https://github.com/awesomekling
Commit: 892c7d980e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6604
3 changed files with 11 additions and 4 deletions
|
|
@ -250,7 +250,7 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record, GC::Ptr<Environ
|
||||||
// 8. Set the PrivateEnvironment of scriptContext to null.
|
// 8. Set the PrivateEnvironment of scriptContext to null.
|
||||||
|
|
||||||
// NOTE: This isn't in the spec, but we require it.
|
// NOTE: This isn't in the spec, but we require it.
|
||||||
script_context->is_strict_mode = script_record.parse_node().is_strict_mode();
|
script_context->is_strict_mode = script_record.is_strict_mode();
|
||||||
|
|
||||||
// 9. Suspend the currently running execution context.
|
// 9. Suspend the currently running execution context.
|
||||||
// 10. Push scriptContext onto the execution context stack; scriptContext is now the running execution context.
|
// 10. Push scriptContext onto the execution context stack; scriptContext is now the running execution context.
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,18 @@ Result<GC::Ref<Script>, Vector<ParserError>> Script::parse(StringView source_tex
|
||||||
if (parser.has_errors())
|
if (parser.has_errors())
|
||||||
return parser.errors();
|
return parser.errors();
|
||||||
|
|
||||||
|
bool strict_mode = script->is_strict_mode();
|
||||||
|
|
||||||
// 3. Return Script Record { [[Realm]]: realm, [[ECMAScriptCode]]: script, [[HostDefined]]: hostDefined }.
|
// 3. Return Script Record { [[Realm]]: realm, [[ECMAScriptCode]]: script, [[HostDefined]]: hostDefined }.
|
||||||
return realm.heap().allocate<Script>(realm, filename, move(script), host_defined);
|
return realm.heap().allocate<Script>(realm, filename, move(script), host_defined, strict_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
Script::Script(Realm& realm, StringView filename, NonnullRefPtr<Program> parse_node, HostDefined* host_defined)
|
Script::Script(Realm& realm, StringView filename, NonnullRefPtr<Program> parse_node, HostDefined* host_defined, bool strict_mode)
|
||||||
: m_realm(realm)
|
: m_realm(realm)
|
||||||
, m_parse_node(move(parse_node))
|
, m_parse_node(move(parse_node))
|
||||||
, m_filename(filename)
|
, m_filename(filename)
|
||||||
, m_host_defined(host_defined)
|
, m_host_defined(host_defined)
|
||||||
|
, m_strict_mode(strict_mode)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,10 @@ public:
|
||||||
HostDefined* host_defined() const { return m_host_defined; }
|
HostDefined* host_defined() const { return m_host_defined; }
|
||||||
StringView filename() const LIFETIME_BOUND { return m_filename; }
|
StringView filename() const LIFETIME_BOUND { return m_filename; }
|
||||||
|
|
||||||
|
[[nodiscard]] bool is_strict_mode() const { return m_strict_mode; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Script(Realm&, StringView filename, NonnullRefPtr<Program>, HostDefined* = nullptr);
|
Script(Realm&, StringView filename, NonnullRefPtr<Program>, HostDefined*, bool strict_mode);
|
||||||
|
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
|
@ -58,6 +60,8 @@ private:
|
||||||
// Needed for potential lookups of modules.
|
// Needed for potential lookups of modules.
|
||||||
ByteString m_filename;
|
ByteString m_filename;
|
||||||
HostDefined* m_host_defined { nullptr }; // [[HostDefined]]
|
HostDefined* m_host_defined { nullptr }; // [[HostDefined]]
|
||||||
|
|
||||||
|
bool m_strict_mode { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue