@ugo-studio/jspp 0.1.4 → 0.1.6
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/dist/analysis/scope.js +17 -0
- package/dist/analysis/typeAnalyzer.js +7 -1
- package/dist/ast/symbols.js +32 -0
- package/dist/ast/types.js +0 -6
- package/dist/cli-utils/args.js +57 -0
- package/dist/cli-utils/colors.js +9 -0
- package/dist/cli-utils/file-utils.js +20 -0
- package/dist/cli-utils/spinner.js +55 -0
- package/dist/cli.js +105 -30
- package/dist/core/codegen/class-handlers.js +10 -6
- package/dist/core/codegen/control-flow-handlers.js +57 -28
- package/dist/core/codegen/declaration-handlers.js +10 -6
- package/dist/core/codegen/expression-handlers.js +206 -61
- package/dist/core/codegen/function-handlers.js +203 -76
- package/dist/core/codegen/helpers.js +125 -28
- package/dist/core/codegen/index.js +23 -15
- package/dist/core/codegen/literal-handlers.js +15 -6
- package/dist/core/codegen/statement-handlers.js +282 -84
- package/dist/core/codegen/visitor.js +3 -1
- package/package.json +1 -1
- package/src/prelude/any_value.hpp +221 -342
- package/src/prelude/any_value_access.hpp +168 -81
- package/src/prelude/any_value_defines.hpp +74 -35
- package/src/prelude/any_value_helpers.hpp +75 -180
- package/src/prelude/exception.hpp +1 -0
- package/src/prelude/exception_helpers.hpp +4 -4
- package/src/prelude/index.hpp +12 -2
- package/src/prelude/library/array.hpp +190 -0
- package/src/prelude/library/console.hpp +6 -5
- package/src/prelude/library/error.hpp +10 -8
- package/src/prelude/library/function.hpp +10 -0
- package/src/prelude/library/global.hpp +20 -0
- package/src/prelude/library/math.hpp +308 -0
- package/src/prelude/library/object.hpp +288 -0
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +39 -0
- package/src/prelude/library/promise.hpp +57 -55
- package/src/prelude/library/symbol.hpp +45 -57
- package/src/prelude/library/timer.hpp +6 -6
- package/src/prelude/types.hpp +54 -0
- package/src/prelude/utils/access.hpp +215 -11
- package/src/prelude/utils/assignment_operators.hpp +99 -0
- package/src/prelude/utils/log_any_value/array.hpp +8 -8
- package/src/prelude/utils/log_any_value/function.hpp +6 -4
- package/src/prelude/utils/log_any_value/object.hpp +41 -24
- package/src/prelude/utils/log_any_value/primitives.hpp +3 -1
- package/src/prelude/utils/operators.hpp +750 -274
- package/src/prelude/utils/well_known_symbols.hpp +12 -0
- package/src/prelude/values/array.hpp +8 -6
- package/src/prelude/values/async_iterator.hpp +79 -0
- package/src/prelude/values/descriptors.hpp +2 -2
- package/src/prelude/values/function.hpp +72 -62
- package/src/prelude/values/helpers/array.hpp +64 -28
- package/src/prelude/values/helpers/async_iterator.hpp +275 -0
- package/src/prelude/values/helpers/function.hpp +81 -92
- package/src/prelude/values/helpers/iterator.hpp +3 -3
- package/src/prelude/values/helpers/object.hpp +54 -9
- package/src/prelude/values/helpers/promise.hpp +13 -6
- package/src/prelude/values/iterator.hpp +1 -1
- package/src/prelude/values/object.hpp +10 -3
- package/src/prelude/values/promise.hpp +7 -11
- package/src/prelude/values/prototypes/array.hpp +851 -12
- package/src/prelude/values/prototypes/async_iterator.hpp +50 -0
- package/src/prelude/values/prototypes/function.hpp +2 -2
- package/src/prelude/values/prototypes/iterator.hpp +5 -5
- package/src/prelude/values/prototypes/number.hpp +153 -0
- package/src/prelude/values/prototypes/object.hpp +2 -2
- package/src/prelude/values/prototypes/promise.hpp +40 -30
- package/src/prelude/values/prototypes/string.hpp +28 -28
- package/src/prelude/values/prototypes/symbol.hpp +20 -3
- package/src/prelude/values/shape.hpp +52 -0
|
@@ -3,101 +3,188 @@
|
|
|
3
3
|
#include "types.hpp"
|
|
4
4
|
#include "any_value.hpp"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
namespace jspp
|
|
7
7
|
{
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
jspp::AnyValue jspp::AnyValue::get_own_property(uint32_t idx) const noexcept
|
|
11
|
-
{
|
|
12
|
-
switch (storage.type)
|
|
8
|
+
AnyValue AnyValue::get_own_property(const std::string &key) const
|
|
13
9
|
{
|
|
14
|
-
|
|
15
|
-
return storage.array->get_property(idx);
|
|
16
|
-
case JsType::String:
|
|
17
|
-
return storage.str->get_property(idx);
|
|
18
|
-
default:
|
|
19
|
-
return get_own_property(std::to_string(idx));
|
|
10
|
+
return get_property_with_receiver(key, *this);
|
|
20
11
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
bool AnyValue::has_property(const std::string &key) const
|
|
13
|
+
{
|
|
14
|
+
switch (get_type())
|
|
15
|
+
{
|
|
16
|
+
case JsType::Object:
|
|
17
|
+
return std::get<std::shared_ptr<JsObject>>(storage)->has_property(key);
|
|
18
|
+
case JsType::Array:
|
|
19
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->has_property(key);
|
|
20
|
+
case JsType::Function:
|
|
21
|
+
return std::get<std::shared_ptr<JsFunction>>(storage)->has_property(key);
|
|
22
|
+
case JsType::Promise:
|
|
23
|
+
// Promises don't have their own props usually, but could.
|
|
24
|
+
return false;
|
|
25
|
+
case JsType::Iterator:
|
|
26
|
+
return false;
|
|
27
|
+
case JsType::AsyncIterator:
|
|
28
|
+
return false;
|
|
29
|
+
case JsType::Symbol:
|
|
30
|
+
return false;
|
|
31
|
+
case JsType::String:
|
|
32
|
+
if (key == "length")
|
|
33
|
+
return true;
|
|
34
|
+
if (JsArray::is_array_index(key))
|
|
35
|
+
{
|
|
36
|
+
uint32_t idx = static_cast<uint32_t>(std::stoull(key));
|
|
37
|
+
return idx < std::get<std::shared_ptr<JsString>>(storage)->value.length();
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
case JsType::Number:
|
|
41
|
+
return false;
|
|
42
|
+
case JsType::Uninitialized:
|
|
43
|
+
Exception::throw_uninitialized_reference("#<Object>");
|
|
44
|
+
return false;
|
|
45
|
+
default:
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
AnyValue AnyValue::get_own_property(uint32_t idx) const
|
|
50
|
+
{
|
|
51
|
+
switch (storage.index())
|
|
52
|
+
{
|
|
53
|
+
case 7: // Array
|
|
54
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->get_property(idx);
|
|
55
|
+
case 5: // String
|
|
56
|
+
return std::get<std::shared_ptr<JsString>>(storage)->get_property(idx);
|
|
57
|
+
case 4: // Number
|
|
58
|
+
return get_own_property(std::to_string(idx));
|
|
59
|
+
default:
|
|
60
|
+
return get_own_property(std::to_string(idx));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
AnyValue AnyValue::get_own_property(const AnyValue &key) const
|
|
64
|
+
{
|
|
65
|
+
if (key.is_number() && is_array())
|
|
66
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->get_property(key.as_double());
|
|
67
|
+
if (key.is_number() && is_string())
|
|
68
|
+
return std::get<std::shared_ptr<JsString>>(storage)->get_property(key.as_double());
|
|
28
69
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
70
|
+
// If the key is a Symbol, use its internal key string
|
|
71
|
+
if (key.is_symbol())
|
|
72
|
+
return get_own_property(key.as_symbol()->key);
|
|
32
73
|
|
|
33
|
-
|
|
34
|
-
}
|
|
74
|
+
return get_own_property(key.to_std_string());
|
|
75
|
+
}
|
|
35
76
|
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
switch (storage.type)
|
|
77
|
+
AnyValue AnyValue::get_property_with_receiver(const std::string &key, const AnyValue &receiver) const
|
|
39
78
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
switch (get_type())
|
|
80
|
+
{
|
|
81
|
+
case JsType::Object:
|
|
82
|
+
return std::get<std::shared_ptr<JsObject>>(storage)->get_property(key, receiver);
|
|
83
|
+
case JsType::Array:
|
|
84
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->get_property(key, receiver);
|
|
85
|
+
case JsType::Function:
|
|
86
|
+
return std::get<std::shared_ptr<JsFunction>>(storage)->get_property(key, receiver);
|
|
87
|
+
case JsType::Promise:
|
|
88
|
+
return std::get<std::shared_ptr<JsPromise>>(storage)->get_property(key, receiver);
|
|
89
|
+
case JsType::Iterator:
|
|
90
|
+
return std::get<std::shared_ptr<JsIterator<AnyValue>>>(storage)->get_property(key, receiver);
|
|
91
|
+
case JsType::AsyncIterator:
|
|
92
|
+
return std::get<std::shared_ptr<JsAsyncIterator<AnyValue>>>(storage)->get_property(key, receiver);
|
|
93
|
+
case JsType::Symbol:
|
|
94
|
+
return std::get<std::shared_ptr<JsSymbol>>(storage)->get_property(key, receiver);
|
|
95
|
+
case JsType::String:
|
|
96
|
+
return std::get<std::shared_ptr<JsString>>(storage)->get_property(key, receiver);
|
|
97
|
+
case JsType::Number:
|
|
98
|
+
{
|
|
99
|
+
auto proto_it = NumberPrototypes::get(key, std::get<double>(storage));
|
|
100
|
+
if (proto_it.has_value())
|
|
101
|
+
{
|
|
102
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), receiver, key);
|
|
103
|
+
}
|
|
104
|
+
return AnyValue::make_undefined();
|
|
105
|
+
}
|
|
106
|
+
case JsType::Undefined:
|
|
107
|
+
throw Exception::make_exception("Cannot read properties of undefined (reading '" + key + "')", "TypeError");
|
|
108
|
+
case JsType::Null:
|
|
109
|
+
throw Exception::make_exception("Cannot read properties of null (reading '" + key + "')", "TypeError");
|
|
110
|
+
case JsType::Uninitialized:
|
|
111
|
+
Exception::throw_uninitialized_reference("#<Object>");
|
|
112
|
+
default:
|
|
113
|
+
return AnyValue::make_undefined();
|
|
114
|
+
}
|
|
60
115
|
}
|
|
61
|
-
}
|
|
62
116
|
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
switch (storage.type)
|
|
117
|
+
AnyValue AnyValue::set_own_property(const std::string &key, const AnyValue &value) const
|
|
66
118
|
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
119
|
+
switch (get_type())
|
|
120
|
+
{
|
|
121
|
+
case JsType::Object:
|
|
122
|
+
return std::get<std::shared_ptr<JsObject>>(storage)->set_property(key, value, *this);
|
|
123
|
+
case JsType::Array:
|
|
124
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->set_property(key, value, *this);
|
|
125
|
+
case JsType::Function:
|
|
126
|
+
return std::get<std::shared_ptr<JsFunction>>(storage)->set_property(key, value, *this);
|
|
127
|
+
case JsType::Promise:
|
|
128
|
+
return std::get<std::shared_ptr<JsPromise>>(storage)->set_property(key, value, *this);
|
|
129
|
+
case JsType::Undefined:
|
|
130
|
+
throw Exception::make_exception("Cannot set properties of undefined (setting '" + key + "')", "TypeError");
|
|
131
|
+
case JsType::Null:
|
|
132
|
+
throw Exception::make_exception("Cannot set properties of null (setting '" + key + "')", "TypeError");
|
|
133
|
+
default:
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
81
136
|
}
|
|
82
|
-
|
|
83
|
-
jspp::AnyValue jspp::AnyValue::set_own_property(uint32_t idx, const AnyValue &value) const
|
|
84
|
-
{
|
|
85
|
-
if (storage.type == JsType::Array)
|
|
137
|
+
AnyValue AnyValue::set_own_property(uint32_t idx, const AnyValue &value) const
|
|
86
138
|
{
|
|
87
|
-
|
|
139
|
+
if (is_array())
|
|
140
|
+
{
|
|
141
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->set_property(idx, value);
|
|
142
|
+
}
|
|
143
|
+
return set_own_property(std::to_string(idx), value);
|
|
88
144
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
|
|
145
|
+
AnyValue AnyValue::set_own_property(const AnyValue &key, const AnyValue &value) const
|
|
146
|
+
{
|
|
147
|
+
if (key.is_number() && is_array())
|
|
148
|
+
{
|
|
149
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->set_property(key.as_double(), value);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// If the key is a Symbol, use its internal key string
|
|
153
|
+
if (key.is_symbol())
|
|
154
|
+
return set_own_property(key.as_symbol()->key, value);
|
|
155
|
+
|
|
156
|
+
return set_own_property(key.to_std_string(), value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
AnyValue AnyValue::call_own_property(const std::string &key, std::span<const AnyValue> args) const
|
|
160
|
+
{
|
|
161
|
+
return get_own_property(key).call((*this), args, key);
|
|
162
|
+
}
|
|
163
|
+
AnyValue AnyValue::call_own_property(uint32_t idx, std::span<const AnyValue> args) const
|
|
94
164
|
{
|
|
95
|
-
|
|
165
|
+
switch (storage.index())
|
|
166
|
+
{
|
|
167
|
+
case 7: // Array
|
|
168
|
+
return std::get<std::shared_ptr<JsArray>>(storage)->get_property(idx).call((*this), args, "[" + std::to_string(idx) + "]");
|
|
169
|
+
case 5: // String
|
|
170
|
+
return std::get<std::shared_ptr<JsString>>(storage)->get_property(idx).call((*this), args, "[" + std::to_string(idx) + "]");
|
|
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
|
+
}
|
|
96
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() + "]");
|
|
97
183
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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);
|
|
101
187
|
|
|
102
|
-
|
|
103
|
-
}
|
|
188
|
+
return call_own_property(key.to_std_string(), args);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -7,16 +7,25 @@
|
|
|
7
7
|
|
|
8
8
|
namespace jspp
|
|
9
9
|
{
|
|
10
|
-
|
|
11
10
|
inline void AnyValue::define_data_property(const std::string &key, const AnyValue &value)
|
|
12
11
|
{
|
|
13
12
|
if (is_object())
|
|
14
13
|
{
|
|
15
|
-
|
|
14
|
+
auto obj = std::get<std::shared_ptr<JsObject>>(storage);
|
|
15
|
+
auto offset = obj->shape->get_offset(key);
|
|
16
|
+
if (offset.has_value())
|
|
17
|
+
{
|
|
18
|
+
obj->storage[offset.value()] = value;
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
{
|
|
22
|
+
obj->shape = obj->shape->transition(key);
|
|
23
|
+
obj->storage.push_back(value);
|
|
24
|
+
}
|
|
16
25
|
}
|
|
17
26
|
else if (is_function())
|
|
18
27
|
{
|
|
19
|
-
storage
|
|
28
|
+
std::get<std::shared_ptr<JsFunction>>(storage)->props[key] = value;
|
|
20
29
|
}
|
|
21
30
|
}
|
|
22
31
|
|
|
@@ -37,42 +46,56 @@ namespace jspp
|
|
|
37
46
|
{
|
|
38
47
|
if (is_object())
|
|
39
48
|
{
|
|
40
|
-
auto
|
|
41
|
-
auto
|
|
42
|
-
|
|
49
|
+
auto obj = std::get<std::shared_ptr<JsObject>>(storage);
|
|
50
|
+
auto offset = obj->shape->get_offset(key);
|
|
51
|
+
|
|
52
|
+
if (offset.has_value())
|
|
43
53
|
{
|
|
44
|
-
auto
|
|
45
|
-
|
|
54
|
+
auto &val = obj->storage[offset.value()];
|
|
55
|
+
if (val.is_accessor_descriptor())
|
|
46
56
|
{
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
auto desc = val.as_accessor_descriptor();
|
|
58
|
+
desc->get = [getter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
59
|
+
{
|
|
60
|
+
return getter.call(thisVal, args);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
{
|
|
65
|
+
auto getFunc = [getter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
66
|
+
{
|
|
67
|
+
return getter.call(thisVal, args);
|
|
68
|
+
};
|
|
69
|
+
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
70
|
+
}
|
|
49
71
|
}
|
|
50
72
|
else
|
|
51
73
|
{
|
|
52
|
-
auto getFunc = [getter](const AnyValue &thisVal,
|
|
74
|
+
auto getFunc = [getter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
53
75
|
{
|
|
54
|
-
return getter.
|
|
76
|
+
return getter.call(thisVal, args);
|
|
55
77
|
};
|
|
56
|
-
|
|
78
|
+
obj->shape = obj->shape->transition(key);
|
|
79
|
+
obj->storage.push_back(AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true));
|
|
57
80
|
}
|
|
58
81
|
}
|
|
59
82
|
else if (is_function())
|
|
60
83
|
{
|
|
61
|
-
auto &props = storage
|
|
84
|
+
auto &props = std::get<std::shared_ptr<JsFunction>>(storage)->props;
|
|
62
85
|
auto it = props.find(key);
|
|
63
86
|
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
64
87
|
{
|
|
65
88
|
auto desc = it->second.as_accessor_descriptor();
|
|
66
|
-
desc->get = [getter](const AnyValue &thisVal,
|
|
89
|
+
desc->get = [getter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
67
90
|
{
|
|
68
|
-
return getter.
|
|
91
|
+
return getter.call(thisVal, args);
|
|
69
92
|
};
|
|
70
93
|
}
|
|
71
94
|
else
|
|
72
95
|
{
|
|
73
|
-
auto getFunc = [getter](const AnyValue &thisVal,
|
|
96
|
+
auto getFunc = [getter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
74
97
|
{
|
|
75
|
-
return getter.
|
|
98
|
+
return getter.call(thisVal, args);
|
|
76
99
|
};
|
|
77
100
|
props[key] = AnyValue::make_accessor_descriptor(getFunc, std::nullopt, true, true);
|
|
78
101
|
}
|
|
@@ -91,50 +114,66 @@ namespace jspp
|
|
|
91
114
|
{
|
|
92
115
|
if (is_object())
|
|
93
116
|
{
|
|
94
|
-
auto
|
|
95
|
-
auto
|
|
96
|
-
|
|
117
|
+
auto obj = std::get<std::shared_ptr<JsObject>>(storage);
|
|
118
|
+
auto offset = obj->shape->get_offset(key);
|
|
119
|
+
|
|
120
|
+
if (offset.has_value())
|
|
97
121
|
{
|
|
98
|
-
auto
|
|
99
|
-
|
|
122
|
+
auto &val = obj->storage[offset.value()];
|
|
123
|
+
if (val.is_accessor_descriptor())
|
|
100
124
|
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
125
|
+
auto desc = val.as_accessor_descriptor();
|
|
126
|
+
desc->set = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
127
|
+
{
|
|
128
|
+
if (args.empty())
|
|
129
|
+
return AnyValue::make_undefined();
|
|
130
|
+
return setter.call(thisVal, args);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else
|
|
134
|
+
{
|
|
135
|
+
auto setFunc = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
136
|
+
{
|
|
137
|
+
if (args.empty())
|
|
138
|
+
return AnyValue::make_undefined();
|
|
139
|
+
return setter.call(thisVal, args);
|
|
140
|
+
};
|
|
141
|
+
obj->storage[offset.value()] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
142
|
+
}
|
|
105
143
|
}
|
|
106
144
|
else
|
|
107
145
|
{
|
|
108
|
-
auto setFunc = [setter](const AnyValue &thisVal,
|
|
146
|
+
auto setFunc = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
109
147
|
{
|
|
110
148
|
if (args.empty())
|
|
111
149
|
return AnyValue::make_undefined();
|
|
112
|
-
return setter.
|
|
150
|
+
return setter.call(thisVal, args);
|
|
113
151
|
};
|
|
114
|
-
|
|
152
|
+
obj->shape = obj->shape->transition(key);
|
|
153
|
+
obj->storage.push_back(AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true));
|
|
115
154
|
}
|
|
116
155
|
}
|
|
117
156
|
else if (is_function())
|
|
118
157
|
{
|
|
119
|
-
auto &props = storage
|
|
158
|
+
auto &props = std::get<std::shared_ptr<JsFunction>>(storage)->props;
|
|
120
159
|
auto it = props.find(key);
|
|
121
160
|
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
122
161
|
{
|
|
123
162
|
auto desc = it->second.as_accessor_descriptor();
|
|
124
|
-
desc->set = [setter](const AnyValue &thisVal,
|
|
163
|
+
desc->set = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
125
164
|
{
|
|
126
165
|
if (args.empty())
|
|
127
166
|
return AnyValue::make_undefined();
|
|
128
|
-
return setter.
|
|
167
|
+
return setter.call(thisVal, args);
|
|
129
168
|
};
|
|
130
169
|
}
|
|
131
170
|
else
|
|
132
171
|
{
|
|
133
|
-
auto setFunc = [setter](const AnyValue &thisVal,
|
|
172
|
+
auto setFunc = [setter](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
134
173
|
{
|
|
135
174
|
if (args.empty())
|
|
136
175
|
return AnyValue::make_undefined();
|
|
137
|
-
return setter.
|
|
176
|
+
return setter.call(thisVal, args);
|
|
138
177
|
};
|
|
139
178
|
props[key] = AnyValue::make_accessor_descriptor(std::nullopt, setFunc, true, true);
|
|
140
179
|
}
|