summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Script.cpp
blob: 14286749df166904270129a88c6ec72e58b79e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibJS/AST.h>
#include <LibJS/Lexer.h>
#include <LibJS/Parser.h>
#include <LibJS/Script.h>

namespace JS {

// 16.1.5 ParseScript ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parse-script
NonnullRefPtr<Script> Script::parse(StringView source_text, Realm& realm, StringView filename)
{
    // 1. Let body be ParseText(sourceText, Script).
    auto body = Parser(Lexer(source_text, filename)).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(realm, move(body)));
}

Script::Script(Realm& realm, NonnullRefPtr<Program> parse_node)
    : m_realm(make_handle(&realm))
    , m_parse_node(move(parse_node))
{
}

Script::~Script()
{
}

}