forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibJS: Start adding a JS::Script class (spec's "Script Record")
- Loading branch information
1 parent
619ee99
commit 612a23d
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
} |