summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Script.h
blob: b11914d0a8eae64f540f40817638c28c3ec2a41f (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
/*
 * 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> parse(StringView source_text, GlobalObject&, StringView filename = {});

    GlobalObject& global_object() { return *m_global_object.cell(); }
    Program const& parse_node() const { return *m_parse_node; }

private:
    Script(GlobalObject&, NonnullRefPtr<Program>);

    Handle<GlobalObject> m_global_object;
    NonnullRefPtr<Program> m_parse_node;
};

}