Skip to content

Commit

Permalink
LibJS: Start adding a JS::Script class (spec's "Script Record")
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Sep 9, 2021
1 parent 619ee99 commit 612a23d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Userland/Libraries/LibJS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ set(SOURCES
Runtime/WeakSet.cpp
Runtime/WeakSetConstructor.cpp
Runtime/WeakSetPrototype.cpp
Script.cpp
SyntaxHighlighter.cpp
Token.cpp
)
Expand Down
26 changes: 26 additions & 0 deletions Userland/Libraries/LibJS/Script.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2021, Andreas Kling <[email protected]>
*
* 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()
{
}

}
33 changes: 33 additions & 0 deletions Userland/Libraries/LibJS/Script.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021, Andreas Kling <[email protected]>
*
* 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;
};

}

0 comments on commit 612a23d

Please sign in to comment.