mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibJS: Implement the ParseScript AO (as JS::Script::parse())
This commit is contained in:
parent
35c4a1ebcb
commit
d823d7da54
2 changed files with 17 additions and 7 deletions
|
@ -4,16 +4,26 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Lexer.h>
|
||||
#include <LibJS/Parser.h>
|
||||
#include <LibJS/Script.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
NonnullRefPtr<Script> Script::create(GlobalObject& global_object, NonnullRefPtr<ASTNode> parse_node)
|
||||
// 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script
|
||||
NonnullRefPtr<Script> Script::parse(StringView source_text, GlobalObject& global_object)
|
||||
{
|
||||
return adopt_ref(*new Script(global_object, move(parse_node)));
|
||||
// 1. Let body be ParseText(sourceText, Script).
|
||||
auto body = Parser(Lexer(source_text)).parse_program();
|
||||
|
||||
// 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)));
|
||||
}
|
||||
|
||||
Script::Script(GlobalObject& global_object, NonnullRefPtr<ASTNode> parse_node)
|
||||
Script::Script(GlobalObject& global_object, NonnullRefPtr<Program> parse_node)
|
||||
: m_global_object(make_handle(&global_object))
|
||||
, m_parse_node(move(parse_node))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue