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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibJS/Runtime/PropertyName.h>
#include <LibJS/Runtime/Value.h>
namespace JS {
class Reference {
public:
Reference() { }
Reference(Value base, const PropertyName& name, bool strict = false)
: m_base(base)
, m_name(name)
, m_strict(strict)
{
}
enum LocalVariableTag { LocalVariable };
Reference(LocalVariableTag, const FlyString& name, bool strict = false)
: m_base(js_null())
, m_name(name)
, m_strict(strict)
, m_local_variable(true)
{
}
enum GlobalVariableTag { GlobalVariable };
Reference(GlobalVariableTag, const FlyString& name, bool strict = false)
: m_base(js_null())
, m_name(name)
, m_strict(strict)
, m_global_variable(true)
{
}
Value base() const { return m_base; }
const PropertyName& name() const { return m_name; }
bool is_strict() const { return m_strict; }
bool is_unresolvable() const { return m_base.is_empty(); }
bool is_property() const
{
return m_base.is_object() || has_primitive_base();
}
bool has_primitive_base() const
{
return m_base.is_boolean() || m_base.is_string() || m_base.is_number();
}
bool is_local_variable() const
{
return m_local_variable;
}
bool is_global_variable() const
{
return m_global_variable;
}
void put(GlobalObject&, Value);
Value get(GlobalObject&);
bool delete_(GlobalObject&);
private:
void throw_reference_error(GlobalObject&);
Value m_base;
PropertyName m_name;
bool m_strict { false };
bool m_local_variable { false };
bool m_global_variable { false };
};
}
|