LibJS: Start adding a JS::Script class (spec's "Script Record")

This commit is contained in:
Andreas Kling 2021-09-09 18:02:31 +02:00
parent 619ee99c34
commit 612a23d6fc
Notes: sideshowbarker 2024-07-18 04:22:20 +09:00
3 changed files with 60 additions and 0 deletions

View File

@ -184,6 +184,7 @@ set(SOURCES
Runtime/WeakSet.cpp Runtime/WeakSet.cpp
Runtime/WeakSetConstructor.cpp Runtime/WeakSetConstructor.cpp
Runtime/WeakSetPrototype.cpp Runtime/WeakSetPrototype.cpp
Script.cpp
SyntaxHighlighter.cpp SyntaxHighlighter.cpp
Token.cpp Token.cpp
) )

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Script.h>
namespace JS {
NonnullRefPtr<Script> Script::create(GlobalObject& global_object, NonnullRefPtr<ASTNode> parse_node)
{
return adopt_ref(*new Script(global_object, move(parse_node)));
}
Script::Script(GlobalObject& global_object, NonnullRefPtr<ASTNode> parse_node)
: m_global_object(make_handle(&global_object))
, m_parse_node(move(parse_node))
{
}
Script::~Script()
{
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibJS/AST.h>
#include <LibJS/Heap/Handle.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace JS {
// 16.1.4 Script Records, https://tc39.es/ecma262/#sec-script-records
class Script : public RefCounted<Script> {
public:
~Script();
static NonnullRefPtr<Script> create(GlobalObject&, NonnullRefPtr<ASTNode> parse_node);
GlobalObject& global_object() { return *m_global_object.cell(); }
ASTNode const& parse_node() const { return *m_parse_node; }
private:
Script(GlobalObject&, NonnullRefPtr<ASTNode>);
Handle<GlobalObject> m_global_object;
NonnullRefPtr<ASTNode> m_parse_node;
};
}