@ugo-studio/jspp 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli-utils/args.js +2 -0
- package/dist/cli.js +1 -1
- package/package.json +1 -1
- package/src/prelude/any_value.hpp +185 -391
- package/src/prelude/any_value_access.hpp +170 -190
- package/src/prelude/any_value_defines.hpp +12 -12
- package/src/prelude/any_value_helpers.hpp +208 -26
- package/src/prelude/exception.hpp +27 -31
- package/src/prelude/exception_helpers.hpp +53 -49
- package/src/prelude/index.hpp +9 -4
- package/src/prelude/library/array.hpp +4 -9
- package/src/prelude/library/console.hpp +112 -112
- package/src/prelude/library/error.hpp +8 -8
- package/src/prelude/library/math.hpp +3 -3
- package/src/prelude/library/object.hpp +12 -24
- package/src/prelude/library/promise.hpp +1 -1
- package/src/prelude/library/symbol.hpp +1 -1
- package/src/prelude/library/timer.hpp +3 -3
- package/src/prelude/types.hpp +178 -130
- package/src/prelude/utils/access.hpp +338 -378
- package/src/prelude/utils/log_any_value/function.hpp +39 -39
- package/src/prelude/utils/log_any_value/log_any_value.hpp +1 -1
- package/src/prelude/utils/operators.hpp +20 -82
- package/src/prelude/utils/well_known_symbols.hpp +14 -15
- package/src/prelude/values/array.hpp +5 -3
- package/src/prelude/values/async_iterator.hpp +3 -1
- package/src/prelude/values/descriptors.hpp +15 -3
- package/src/prelude/values/function.hpp +5 -9
- package/src/prelude/values/helpers/array.hpp +208 -219
- package/src/prelude/values/helpers/async_iterator.hpp +7 -11
- package/src/prelude/values/helpers/function.hpp +12 -17
- package/src/prelude/values/helpers/iterator.hpp +108 -107
- package/src/prelude/values/helpers/object.hpp +104 -109
- package/src/prelude/values/helpers/promise.hpp +185 -119
- package/src/prelude/values/helpers/string.hpp +7 -10
- package/src/prelude/values/helpers/symbol.hpp +21 -23
- package/src/prelude/values/iterator.hpp +4 -1
- package/src/prelude/values/object.hpp +6 -4
- package/src/prelude/values/promise.hpp +5 -2
- package/src/prelude/values/prototypes/array.hpp +22 -22
- package/src/prelude/values/prototypes/async_iterator.hpp +3 -10
- package/src/prelude/values/prototypes/iterator.hpp +51 -58
- package/src/prelude/values/prototypes/promise.hpp +32 -28
- package/src/prelude/values/prototypes/string.hpp +5 -5
- package/src/prelude/values/prototypes/symbol.hpp +1 -1
- package/src/prelude/values/string.hpp +3 -1
- package/src/prelude/values/symbol.hpp +101 -102
|
@@ -1,190 +1,170 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "any_value.hpp"
|
|
5
|
-
|
|
6
|
-
namespace jspp
|
|
7
|
-
{
|
|
8
|
-
AnyValue AnyValue::get_own_property(const std::string &key) const
|
|
9
|
-
{
|
|
10
|
-
return get_property_with_receiver(key, *this);
|
|
11
|
-
}
|
|
12
|
-
bool AnyValue::has_property(const std::string &key) const
|
|
13
|
-
{
|
|
14
|
-
switch (get_type())
|
|
15
|
-
{
|
|
16
|
-
case JsType::Object:
|
|
17
|
-
return
|
|
18
|
-
case JsType::Array:
|
|
19
|
-
return
|
|
20
|
-
case JsType::Function:
|
|
21
|
-
return
|
|
22
|
-
case JsType::Promise:
|
|
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
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case JsType::
|
|
82
|
-
return
|
|
83
|
-
case JsType::
|
|
84
|
-
return
|
|
85
|
-
case JsType::
|
|
86
|
-
return
|
|
87
|
-
case JsType::
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
case JsType::
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
case 4: // Number
|
|
172
|
-
return call_own_property(std::to_string(idx), args);
|
|
173
|
-
default:
|
|
174
|
-
return call_own_property(std::to_string(idx), args);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
AnyValue AnyValue::call_own_property(const AnyValue &key, std::span<const AnyValue> args) const
|
|
178
|
-
{
|
|
179
|
-
if (key.is_number() && is_array())
|
|
180
|
-
return std::get<std::shared_ptr<JsArray>>(storage)->get_property(key.as_double()).call((*this), args, "[" + key.to_std_string() + "]");
|
|
181
|
-
if (key.is_number() && is_string())
|
|
182
|
-
return std::get<std::shared_ptr<JsString>>(storage)->get_property(key.as_double()).call((*this), args, "[" + key.to_std_string() + "]");
|
|
183
|
-
|
|
184
|
-
// If the key is a Symbol, use its internal key string
|
|
185
|
-
if (key.is_symbol())
|
|
186
|
-
return call_own_property(key.as_symbol()->key, args);
|
|
187
|
-
|
|
188
|
-
return call_own_property(key.to_std_string(), args);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
|
|
6
|
+
namespace jspp
|
|
7
|
+
{
|
|
8
|
+
inline AnyValue AnyValue::get_own_property(const std::string &key) const
|
|
9
|
+
{
|
|
10
|
+
return get_property_with_receiver(key, *this);
|
|
11
|
+
}
|
|
12
|
+
inline bool AnyValue::has_property(const std::string &key) const
|
|
13
|
+
{
|
|
14
|
+
switch (get_type())
|
|
15
|
+
{
|
|
16
|
+
case JsType::Object:
|
|
17
|
+
return as_object()->has_property(key);
|
|
18
|
+
case JsType::Array:
|
|
19
|
+
return as_array()->has_property(key);
|
|
20
|
+
case JsType::Function:
|
|
21
|
+
return as_function()->has_property(key);
|
|
22
|
+
case JsType::Promise:
|
|
23
|
+
return false;
|
|
24
|
+
case JsType::Iterator:
|
|
25
|
+
return false;
|
|
26
|
+
case JsType::AsyncIterator:
|
|
27
|
+
return false;
|
|
28
|
+
case JsType::Symbol:
|
|
29
|
+
return false;
|
|
30
|
+
case JsType::String:
|
|
31
|
+
if (key == "length")
|
|
32
|
+
return true;
|
|
33
|
+
if (JsArray::is_array_index(key))
|
|
34
|
+
{
|
|
35
|
+
uint32_t idx = static_cast<uint32_t>(std::stoull(key));
|
|
36
|
+
return idx < as_string()->value.length();
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
case JsType::Number:
|
|
40
|
+
return false;
|
|
41
|
+
case JsType::Uninitialized:
|
|
42
|
+
Exception::throw_uninitialized_reference("#<Object>");
|
|
43
|
+
return false;
|
|
44
|
+
default:
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
inline AnyValue AnyValue::get_own_property(uint32_t idx) const
|
|
49
|
+
{
|
|
50
|
+
if (is_array()) return as_array()->get_property(idx);
|
|
51
|
+
if (is_string()) return as_string()->get_property(idx);
|
|
52
|
+
return get_own_property(std::to_string(idx));
|
|
53
|
+
}
|
|
54
|
+
inline AnyValue AnyValue::get_own_property(const AnyValue &key) const
|
|
55
|
+
{
|
|
56
|
+
if (key.is_number() && is_array())
|
|
57
|
+
return as_array()->get_property(key.as_double());
|
|
58
|
+
if (key.is_number() && is_string())
|
|
59
|
+
return as_string()->get_property(key.as_double());
|
|
60
|
+
|
|
61
|
+
if (key.is_symbol())
|
|
62
|
+
return get_own_property(key.as_symbol()->key);
|
|
63
|
+
|
|
64
|
+
return get_own_property(key.to_std_string());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
inline AnyValue AnyValue::get_property_with_receiver(const std::string &key, const AnyValue &receiver) const
|
|
68
|
+
{
|
|
69
|
+
switch (get_type())
|
|
70
|
+
{
|
|
71
|
+
case JsType::Object:
|
|
72
|
+
return as_object()->get_property(key, receiver);
|
|
73
|
+
case JsType::Array:
|
|
74
|
+
return as_array()->get_property(key, receiver);
|
|
75
|
+
case JsType::Function:
|
|
76
|
+
return as_function()->get_property(key, receiver);
|
|
77
|
+
case JsType::Promise:
|
|
78
|
+
return as_promise()->get_property(key, receiver);
|
|
79
|
+
case JsType::Iterator:
|
|
80
|
+
return static_cast<JsIterator<AnyValue>*>(get_ptr())->get_property(key, receiver);
|
|
81
|
+
case JsType::AsyncIterator:
|
|
82
|
+
return static_cast<JsAsyncIterator<AnyValue>*>(get_ptr())->get_property(key, receiver);
|
|
83
|
+
case JsType::Symbol:
|
|
84
|
+
return as_symbol()->get_property(key, receiver);
|
|
85
|
+
case JsType::String:
|
|
86
|
+
return as_string()->get_property(key, receiver);
|
|
87
|
+
case JsType::Number:
|
|
88
|
+
{
|
|
89
|
+
auto proto_it = NumberPrototypes::get(key, as_double());
|
|
90
|
+
if (proto_it.has_value())
|
|
91
|
+
{
|
|
92
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), receiver, key);
|
|
93
|
+
}
|
|
94
|
+
return Constants::UNDEFINED;
|
|
95
|
+
}
|
|
96
|
+
case JsType::Undefined:
|
|
97
|
+
throw Exception::make_exception("Cannot read properties of undefined (reading '" + key + "')", "TypeError");
|
|
98
|
+
case JsType::Null:
|
|
99
|
+
throw Exception::make_exception("Cannot read properties of null (reading '" + key + "')", "TypeError");
|
|
100
|
+
case JsType::Uninitialized:
|
|
101
|
+
Exception::throw_uninitialized_reference("#<Object>");
|
|
102
|
+
default:
|
|
103
|
+
return Constants::UNDEFINED;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
inline AnyValue AnyValue::set_own_property(const std::string &key, const AnyValue &value) const
|
|
108
|
+
{
|
|
109
|
+
switch (get_type())
|
|
110
|
+
{
|
|
111
|
+
case JsType::Object:
|
|
112
|
+
return as_object()->set_property(key, value, *this);
|
|
113
|
+
case JsType::Array:
|
|
114
|
+
return as_array()->set_property(key, value, *this);
|
|
115
|
+
case JsType::Function:
|
|
116
|
+
return as_function()->set_property(key, value, *this);
|
|
117
|
+
case JsType::Promise:
|
|
118
|
+
return as_promise()->set_property(key, value, *this);
|
|
119
|
+
case JsType::Undefined:
|
|
120
|
+
throw Exception::make_exception("Cannot set properties of undefined (setting '" + key + "')", "TypeError");
|
|
121
|
+
case JsType::Null:
|
|
122
|
+
throw Exception::make_exception("Cannot set properties of null (setting '" + key + "')", "TypeError");
|
|
123
|
+
default:
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
inline AnyValue AnyValue::set_own_property(uint32_t idx, const AnyValue &value) const
|
|
128
|
+
{
|
|
129
|
+
if (is_array())
|
|
130
|
+
{
|
|
131
|
+
return as_array()->set_property(idx, value);
|
|
132
|
+
}
|
|
133
|
+
return set_own_property(std::to_string(idx), value);
|
|
134
|
+
}
|
|
135
|
+
inline AnyValue AnyValue::set_own_property(const AnyValue &key, const AnyValue &value) const
|
|
136
|
+
{
|
|
137
|
+
if (key.is_number() && is_array())
|
|
138
|
+
{
|
|
139
|
+
return as_array()->set_property(key.as_double(), value);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (key.is_symbol())
|
|
143
|
+
return set_own_property(key.as_symbol()->key, value);
|
|
144
|
+
|
|
145
|
+
return set_own_property(key.to_std_string(), value);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
inline AnyValue AnyValue::call_own_property(const std::string &key, std::span<const AnyValue> args) const
|
|
149
|
+
{
|
|
150
|
+
return get_own_property(key).call((*this), args, key);
|
|
151
|
+
}
|
|
152
|
+
inline AnyValue AnyValue::call_own_property(uint32_t idx, std::span<const AnyValue> args) const
|
|
153
|
+
{
|
|
154
|
+
if (is_array()) return as_array()->get_property(idx).call((*this), args, "[" + std::to_string(idx) + "]");
|
|
155
|
+
if (is_string()) return as_string()->get_property(idx).call((*this), args, "[" + std::to_string(idx) + "]");
|
|
156
|
+
return call_own_property(std::to_string(idx), args);
|
|
157
|
+
}
|
|
158
|
+
inline AnyValue AnyValue::call_own_property(const AnyValue &key, std::span<const AnyValue> args) const
|
|
159
|
+
{
|
|
160
|
+
if (key.is_number() && is_array())
|
|
161
|
+
return as_array()->get_property(key.as_double()).call((*this), args, "[" + key.to_std_string() + "]");
|
|
162
|
+
if (key.is_number() && is_string())
|
|
163
|
+
return as_string()->get_property(key.as_double()).call((*this), args, "[" + key.to_std_string() + "]");
|
|
164
|
+
|
|
165
|
+
if (key.is_symbol())
|
|
166
|
+
return call_own_property(key.as_symbol()->key, args);
|
|
167
|
+
|
|
168
|
+
return call_own_property(key.to_std_string(), args);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -11,7 +11,7 @@ namespace jspp
|
|
|
11
11
|
{
|
|
12
12
|
if (is_object())
|
|
13
13
|
{
|
|
14
|
-
auto obj =
|
|
14
|
+
auto obj = as_object();
|
|
15
15
|
auto offset = obj->shape->get_offset(key);
|
|
16
16
|
if (offset.has_value())
|
|
17
17
|
{
|
|
@@ -25,7 +25,7 @@ namespace jspp
|
|
|
25
25
|
}
|
|
26
26
|
else if (is_function())
|
|
27
27
|
{
|
|
28
|
-
|
|
28
|
+
as_function()->props[key] = value;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -46,7 +46,7 @@ namespace jspp
|
|
|
46
46
|
{
|
|
47
47
|
if (is_object())
|
|
48
48
|
{
|
|
49
|
-
auto obj =
|
|
49
|
+
auto obj = as_object();
|
|
50
50
|
auto offset = obj->shape->get_offset(key);
|
|
51
51
|
|
|
52
52
|
if (offset.has_value())
|
|
@@ -81,7 +81,7 @@ namespace jspp
|
|
|
81
81
|
}
|
|
82
82
|
else if (is_function())
|
|
83
83
|
{
|
|
84
|
-
auto &props =
|
|
84
|
+
auto &props = as_function()->props;
|
|
85
85
|
auto it = props.find(key);
|
|
86
86
|
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
87
87
|
{
|
|
@@ -114,7 +114,7 @@ namespace jspp
|
|
|
114
114
|
{
|
|
115
115
|
if (is_object())
|
|
116
116
|
{
|
|
117
|
-
auto obj =
|
|
117
|
+
auto obj = as_object();
|
|
118
118
|
auto offset = obj->shape->get_offset(key);
|
|
119
119
|
|
|
120
120
|
if (offset.has_value())
|
|
@@ -126,7 +126,7 @@ namespace jspp
|
|
|
126
126
|
desc->set = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
127
127
|
{
|
|
128
128
|
if (args.empty())
|
|
129
|
-
return
|
|
129
|
+
return Constants::UNDEFINED;
|
|
130
130
|
return setter.call(thisVal, args);
|
|
131
131
|
};
|
|
132
132
|
}
|
|
@@ -135,7 +135,7 @@ namespace jspp
|
|
|
135
135
|
auto setFunc = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
136
136
|
{
|
|
137
137
|
if (args.empty())
|
|
138
|
-
return
|
|
138
|
+
return Constants::UNDEFINED;
|
|
139
139
|
return setter.call(thisVal, args);
|
|
140
140
|
};
|
|
141
141
|
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
@@ -146,7 +146,7 @@ namespace jspp
|
|
|
146
146
|
auto setFunc = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
147
147
|
{
|
|
148
148
|
if (args.empty())
|
|
149
|
-
return
|
|
149
|
+
return Constants::UNDEFINED;
|
|
150
150
|
return setter.call(thisVal, args);
|
|
151
151
|
};
|
|
152
152
|
obj->shape = obj->shape->transition(key);
|
|
@@ -155,7 +155,7 @@ namespace jspp
|
|
|
155
155
|
}
|
|
156
156
|
else if (is_function())
|
|
157
157
|
{
|
|
158
|
-
auto &props =
|
|
158
|
+
auto &props = as_function()->props;
|
|
159
159
|
auto it = props.find(key);
|
|
160
160
|
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
161
161
|
{
|
|
@@ -163,7 +163,7 @@ namespace jspp
|
|
|
163
163
|
desc->set = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
164
164
|
{
|
|
165
165
|
if (args.empty())
|
|
166
|
-
return
|
|
166
|
+
return Constants::UNDEFINED;
|
|
167
167
|
return setter.call(thisVal, args);
|
|
168
168
|
};
|
|
169
169
|
}
|
|
@@ -172,7 +172,7 @@ namespace jspp
|
|
|
172
172
|
auto setFunc = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
173
173
|
{
|
|
174
174
|
if (args.empty())
|
|
175
|
-
return
|
|
175
|
+
return Constants::UNDEFINED;
|
|
176
176
|
return setter.call(thisVal, args);
|
|
177
177
|
};
|
|
178
178
|
props[key] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
@@ -187,4 +187,4 @@ namespace jspp
|
|
|
187
187
|
else
|
|
188
188
|
define_setter(key.to_std_string(), setter);
|
|
189
189
|
}
|
|
190
|
-
}
|
|
190
|
+
}
|