mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:17:46 +00:00
LibJS+LibWeb: Make JS::Script and Web::HTML::ClassicScript use Realms
The spec wants Script Records to have a Realm, not a GlobalObject.
This commit is contained in:
parent
673fc02ac5
commit
106f295916
5 changed files with 17 additions and 16 deletions
|
@ -12,7 +12,7 @@
|
|||
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, StringView filename)
|
||||
NonnullRefPtr<Script> Script::parse(StringView source_text, Realm& realm, StringView filename)
|
||||
{
|
||||
// 1. Let body be ParseText(sourceText, Script).
|
||||
auto body = Parser(Lexer(source_text, filename)).parse_program();
|
||||
|
@ -20,11 +20,11 @@ NonnullRefPtr<Script> Script::parse(StringView source_text, GlobalObject& global
|
|||
// FIXME: 2. If body is a List of errors, return body.
|
||||
|
||||
// 3. Return Script Record { [[Realm]]: realm, [[ECMAScriptCode]]: body, [[HostDefined]]: hostDefined }.
|
||||
return adopt_ref(*new Script(global_object, move(body)));
|
||||
return adopt_ref(*new Script(realm, move(body)));
|
||||
}
|
||||
|
||||
Script::Script(GlobalObject& global_object, NonnullRefPtr<Program> parse_node)
|
||||
: m_global_object(make_handle(&global_object))
|
||||
Script::Script(Realm& realm, NonnullRefPtr<Program> parse_node)
|
||||
: m_realm(make_handle(&realm))
|
||||
, m_parse_node(move(parse_node))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -18,16 +18,16 @@ namespace JS {
|
|||
class Script : public RefCounted<Script> {
|
||||
public:
|
||||
~Script();
|
||||
static NonnullRefPtr<Script> parse(StringView source_text, GlobalObject&, StringView filename = {});
|
||||
static NonnullRefPtr<Script> parse(StringView source_text, Realm&, StringView filename = {});
|
||||
|
||||
GlobalObject& global_object() { return *m_global_object.cell(); }
|
||||
Realm& realm() { return *m_realm.cell(); }
|
||||
Program const& parse_node() const { return *m_parse_node; }
|
||||
|
||||
private:
|
||||
Script(GlobalObject&, NonnullRefPtr<Program>);
|
||||
Script(Realm&, NonnullRefPtr<Program>);
|
||||
|
||||
Handle<GlobalObject> m_global_object;
|
||||
NonnullRefPtr<Program> m_parse_node;
|
||||
Handle<Realm> m_realm; // [[Realm]]
|
||||
NonnullRefPtr<Program> m_parse_node; // [[ECMAScriptCode]]
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue