diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-07 18:25:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-07 19:16:46 +0100 |
commit | 6ddbe8f953c77231a609ab9d12ee0e46d60fb0c8 (patch) | |
tree | da8e885db4acdf9ffb21af6cd819cd8940bc98e5 | |
parent | 77a1ef06a489ba66f9d9171a0d18d1262767f70b (diff) | |
download | serenity-6ddbe8f953c77231a609ab9d12ee0e46d60fb0c8.zip |
LibJS: Add [[HostDefined]] internal slot to Script objects
In C++, this is a raw pointer to a Script::HostDefined.
-rw-r--r-- | Userland/Libraries/LibJS/Script.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Script.h | 13 |
2 files changed, 13 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Script.cpp b/Userland/Libraries/LibJS/Script.cpp index 11423225c5..bc9b89b3bb 100644 --- a/Userland/Libraries/LibJS/Script.cpp +++ b/Userland/Libraries/LibJS/Script.cpp @@ -12,7 +12,7 @@ namespace JS { // 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script -Result<NonnullRefPtr<Script>, Vector<Parser::Error>> Script::parse(StringView source_text, Realm& realm, StringView filename) +Result<NonnullRefPtr<Script>, Vector<Parser::Error>> Script::parse(StringView source_text, Realm& realm, StringView filename, HostDefined* host_defined) { // 1. Let body be ParseText(sourceText, Script). auto parser = Parser(Lexer(source_text, filename)); @@ -23,14 +23,15 @@ Result<NonnullRefPtr<Script>, Vector<Parser::Error>> Script::parse(StringView so return parser.errors(); // 3. Return Script Record { [[Realm]]: realm, [[ECMAScriptCode]]: body, [[HostDefined]]: hostDefined }. - return adopt_ref(*new Script(realm, filename, move(body))); + return adopt_ref(*new Script(realm, filename, move(body), host_defined)); } -Script::Script(Realm& realm, StringView filename, NonnullRefPtr<Program> parse_node) +Script::Script(Realm& realm, StringView filename, NonnullRefPtr<Program> parse_node, HostDefined* host_defined) : m_vm(realm.vm()) , m_realm(make_handle(&realm)) , m_parse_node(move(parse_node)) , m_filename(filename) + , m_host_defined(host_defined) { } diff --git a/Userland/Libraries/LibJS/Script.h b/Userland/Libraries/LibJS/Script.h index 6fa37e8dd3..acc5b4a619 100644 --- a/Userland/Libraries/LibJS/Script.h +++ b/Userland/Libraries/LibJS/Script.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -20,17 +20,21 @@ class Script : public RefCounted<Script> , public Weakable<Script> { public: + struct HostDefined { + virtual ~HostDefined() = default; + }; + ~Script(); - static Result<NonnullRefPtr<Script>, Vector<Parser::Error>> parse(StringView source_text, Realm&, StringView filename = {}); + static Result<NonnullRefPtr<Script>, Vector<Parser::Error>> parse(StringView source_text, Realm&, StringView filename = {}, HostDefined* = nullptr); Realm& realm() { return *m_realm.cell(); } Program const& parse_node() const { return *m_parse_node; } + HostDefined* host_defined() { return m_host_defined; } StringView filename() const { return m_filename; } private: - Script(Realm&, StringView filename, NonnullRefPtr<Program>); - + Script(Realm&, StringView filename, NonnullRefPtr<Program>, HostDefined* = nullptr); // Handles are not safe unless we keep the VM alive. NonnullRefPtr<VM> m_vm; @@ -39,6 +43,7 @@ private: // Needed for potential lookups of modules. String m_filename; + HostDefined* m_host_defined { nullptr }; // [[HostDefined]] }; } |