@ugo-studio/jspp 0.2.8 → 0.3.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/dist/analysis/typeAnalyzer.js +42 -27
- package/dist/core/codegen/class-handlers.js +6 -6
- package/dist/core/codegen/control-flow-handlers.js +4 -4
- package/dist/core/codegen/declaration-handlers.js +21 -3
- package/dist/core/codegen/destructuring-handlers.js +187 -0
- package/dist/core/codegen/expression-handlers.js +7 -0
- package/dist/core/codegen/function-handlers.js +58 -36
- package/dist/core/codegen/helpers.js +288 -52
- package/dist/core/codegen/index.js +7 -4
- package/dist/core/codegen/statement-handlers.js +43 -23
- package/package.json +1 -1
- package/scripts/precompile-headers.ts +13 -5
- package/src/prelude/any_value.hpp +362 -361
- package/src/prelude/any_value_access.hpp +170 -170
- package/src/prelude/any_value_defines.hpp +189 -189
- package/src/prelude/any_value_helpers.hpp +374 -365
- package/src/prelude/library/array.hpp +185 -185
- package/src/prelude/library/console.hpp +111 -111
- package/src/prelude/library/error.hpp +112 -112
- package/src/prelude/library/function.hpp +10 -10
- package/src/prelude/library/math.hpp +307 -307
- package/src/prelude/library/object.hpp +275 -275
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +39 -39
- package/src/prelude/library/promise.hpp +123 -123
- package/src/prelude/library/symbol.hpp +52 -52
- package/src/prelude/library/timer.hpp +91 -91
- package/src/prelude/types.hpp +178 -178
- package/src/prelude/utils/access.hpp +411 -393
- package/src/prelude/utils/operators.hpp +336 -329
- package/src/prelude/values/array.hpp +0 -1
- package/src/prelude/values/async_iterator.hpp +83 -81
- package/src/prelude/values/function.hpp +82 -82
- package/src/prelude/values/helpers/array.hpp +198 -208
- package/src/prelude/values/helpers/async_iterator.hpp +275 -271
- package/src/prelude/values/helpers/function.hpp +108 -108
- package/src/prelude/values/helpers/iterator.hpp +144 -107
- package/src/prelude/values/helpers/promise.hpp +253 -253
- package/src/prelude/values/helpers/string.hpp +37 -47
- package/src/prelude/values/iterator.hpp +32 -5
- package/src/prelude/values/promise.hpp +72 -72
- package/src/prelude/values/prototypes/array.hpp +54 -42
- package/src/prelude/values/prototypes/iterator.hpp +201 -74
- package/src/prelude/values/prototypes/promise.hpp +196 -196
- package/src/prelude/values/prototypes/string.hpp +564 -542
- package/src/prelude/values/string.hpp +25 -26
|
@@ -1,209 +1,199 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "values/array.hpp"
|
|
5
|
-
#include "exception.hpp"
|
|
6
|
-
#include "any_value.hpp"
|
|
7
|
-
#include "values/prototypes/array.hpp"
|
|
8
|
-
|
|
9
|
-
inline jspp::JsArray::JsArray() : proto(Constants::Null), length(0) {}
|
|
10
|
-
inline jspp::JsArray::JsArray(const std::vector<jspp::AnyValue> &items) : dense(items), proto(Constants::Null), length(items.size()) {}
|
|
11
|
-
inline jspp::JsArray::JsArray(std::vector<jspp::AnyValue> &&items) : dense(std::move(items)), proto(Constants::Null), length(dense.size()) {}
|
|
12
|
-
|
|
13
|
-
inline std::string jspp::JsArray::to_std_string() const
|
|
14
|
-
{
|
|
15
|
-
if (length == 0)
|
|
16
|
-
{
|
|
17
|
-
return "";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
std::string result = "";
|
|
21
|
-
for (uint64_t i = 0; i < length; ++i)
|
|
22
|
-
{
|
|
23
|
-
AnyValue itemVal = Constants::UNINITIALIZED;
|
|
24
|
-
if (i < dense.size())
|
|
25
|
-
{
|
|
26
|
-
itemVal = dense[i];
|
|
27
|
-
}
|
|
28
|
-
else
|
|
29
|
-
{
|
|
30
|
-
auto it = sparse.find(static_cast<uint32_t>(i));
|
|
31
|
-
if (it != sparse.end())
|
|
32
|
-
{
|
|
33
|
-
itemVal = it->second;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!itemVal.is_uninitialized())
|
|
38
|
-
{
|
|
39
|
-
if (!itemVal.is_undefined() && !itemVal.is_null())
|
|
40
|
-
{
|
|
41
|
-
result += itemVal.to_std_string();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (i < length - 1)
|
|
46
|
-
{
|
|
47
|
-
result += ",";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
inline
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (key
|
|
66
|
-
return true;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
return true;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
{
|
|
200
|
-
dense.resize(idx + 1, Constants::UNINITIALIZED);
|
|
201
|
-
dense[idx] = value;
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
else
|
|
205
|
-
{
|
|
206
|
-
sparse[idx] = value;
|
|
207
|
-
return value;
|
|
208
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "values/array.hpp"
|
|
5
|
+
#include "exception.hpp"
|
|
6
|
+
#include "any_value.hpp"
|
|
7
|
+
#include "values/prototypes/array.hpp"
|
|
8
|
+
|
|
9
|
+
inline jspp::JsArray::JsArray() : proto(Constants::Null), length(0) {}
|
|
10
|
+
inline jspp::JsArray::JsArray(const std::vector<jspp::AnyValue> &items) : dense(items), proto(Constants::Null), length(items.size()) {}
|
|
11
|
+
inline jspp::JsArray::JsArray(std::vector<jspp::AnyValue> &&items) : dense(std::move(items)), proto(Constants::Null), length(dense.size()) {}
|
|
12
|
+
|
|
13
|
+
inline std::string jspp::JsArray::to_std_string() const
|
|
14
|
+
{
|
|
15
|
+
if (length == 0)
|
|
16
|
+
{
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
std::string result = "";
|
|
21
|
+
for (uint64_t i = 0; i < length; ++i)
|
|
22
|
+
{
|
|
23
|
+
AnyValue itemVal = Constants::UNINITIALIZED;
|
|
24
|
+
if (i < dense.size())
|
|
25
|
+
{
|
|
26
|
+
itemVal = dense[i];
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
{
|
|
30
|
+
auto it = sparse.find(static_cast<uint32_t>(i));
|
|
31
|
+
if (it != sparse.end())
|
|
32
|
+
{
|
|
33
|
+
itemVal = it->second;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!itemVal.is_uninitialized())
|
|
38
|
+
{
|
|
39
|
+
if (!itemVal.is_undefined() && !itemVal.is_null())
|
|
40
|
+
{
|
|
41
|
+
result += itemVal.to_std_string();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (i < length - 1)
|
|
46
|
+
{
|
|
47
|
+
result += ",";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
inline bool jspp::JsArray::has_property(const std::string &key) const
|
|
54
|
+
{
|
|
55
|
+
if (key == "length")
|
|
56
|
+
return true;
|
|
57
|
+
if (is_array_index(key))
|
|
58
|
+
{
|
|
59
|
+
uint32_t idx = static_cast<uint32_t>(std::stoull(key));
|
|
60
|
+
if (idx < dense.size())
|
|
61
|
+
return !dense[idx].is_uninitialized();
|
|
62
|
+
if (sparse.find(idx) != sparse.end())
|
|
63
|
+
return !sparse.at(idx).is_uninitialized();
|
|
64
|
+
}
|
|
65
|
+
if (props.find(key) != props.end())
|
|
66
|
+
return true;
|
|
67
|
+
|
|
68
|
+
if (!proto.is_null() && !proto.is_undefined())
|
|
69
|
+
{
|
|
70
|
+
if (proto.has_property(key))
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (ArrayPrototypes::get(key).has_value())
|
|
75
|
+
return true;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
inline jspp::AnyValue jspp::JsArray::get_property(const std::string &key, const AnyValue &thisVal)
|
|
80
|
+
{
|
|
81
|
+
if (
|
|
82
|
+
!key.empty() && std::isdigit(static_cast<unsigned char>(key[0]))
|
|
83
|
+
&& is_array_index(key))
|
|
84
|
+
{
|
|
85
|
+
uint32_t idx = static_cast<uint32_t>(std::stoull(key));
|
|
86
|
+
return get_property(idx);
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
{
|
|
90
|
+
auto it = props.find(key);
|
|
91
|
+
if (it == props.end())
|
|
92
|
+
{
|
|
93
|
+
if (key == "length")
|
|
94
|
+
{
|
|
95
|
+
auto proto_it = ArrayPrototypes::get(key);
|
|
96
|
+
if (proto_it.has_value())
|
|
97
|
+
{
|
|
98
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!proto.is_null() && !proto.is_undefined())
|
|
103
|
+
{
|
|
104
|
+
if (proto.has_property(key))
|
|
105
|
+
{
|
|
106
|
+
return proto.get_property_with_receiver(key, thisVal);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
auto proto_it = ArrayPrototypes::get(key);
|
|
111
|
+
if (proto_it.has_value())
|
|
112
|
+
{
|
|
113
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key);
|
|
114
|
+
}
|
|
115
|
+
return Constants::UNDEFINED;
|
|
116
|
+
}
|
|
117
|
+
return AnyValue::resolve_property_for_read(it->second, thisVal, key);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
inline jspp::AnyValue jspp::JsArray::get_property(uint32_t idx)
|
|
122
|
+
{
|
|
123
|
+
if (idx < dense.size())
|
|
124
|
+
{
|
|
125
|
+
const auto &val = dense[idx];
|
|
126
|
+
return val.is_uninitialized() ? Constants::UNDEFINED : val;
|
|
127
|
+
}
|
|
128
|
+
const auto &it = sparse.find(idx);
|
|
129
|
+
if (it != sparse.end())
|
|
130
|
+
{
|
|
131
|
+
const auto &val = it->second;
|
|
132
|
+
return val.is_uninitialized() ? Constants::UNDEFINED : val;
|
|
133
|
+
}
|
|
134
|
+
return Constants::UNDEFINED;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
inline jspp::AnyValue jspp::JsArray::set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal)
|
|
138
|
+
{
|
|
139
|
+
if (
|
|
140
|
+
!key.empty() && std::isdigit(static_cast<unsigned char>(key[0]))
|
|
141
|
+
&& is_array_index(key))
|
|
142
|
+
{
|
|
143
|
+
uint32_t idx = static_cast<uint32_t>(std::stoull(key));
|
|
144
|
+
return set_property(idx, value);
|
|
145
|
+
}
|
|
146
|
+
else
|
|
147
|
+
{
|
|
148
|
+
auto proto_val_opt = ArrayPrototypes::get(key);
|
|
149
|
+
|
|
150
|
+
if (proto_val_opt.has_value())
|
|
151
|
+
{
|
|
152
|
+
auto proto_value = proto_val_opt.value();
|
|
153
|
+
if (proto_value.is_accessor_descriptor())
|
|
154
|
+
{
|
|
155
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
156
|
+
}
|
|
157
|
+
if (proto_value.is_data_descriptor() && !proto_value.as_data_descriptor()->writable)
|
|
158
|
+
{
|
|
159
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
auto it = props.find(key);
|
|
164
|
+
if (it != props.end())
|
|
165
|
+
{
|
|
166
|
+
return AnyValue::resolve_property_for_write(it->second, thisVal, value, key);
|
|
167
|
+
}
|
|
168
|
+
else
|
|
169
|
+
{
|
|
170
|
+
props[key] = value;
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
inline jspp::AnyValue jspp::JsArray::set_property(uint32_t idx, const AnyValue &value)
|
|
177
|
+
{
|
|
178
|
+
uint64_t newLen = static_cast<uint64_t>(idx) + 1;
|
|
179
|
+
if (newLen > length)
|
|
180
|
+
length = newLen;
|
|
181
|
+
|
|
182
|
+
const uint32_t DENSE_GROW_THRESHOLD = 1024;
|
|
183
|
+
if (idx < dense.size())
|
|
184
|
+
{
|
|
185
|
+
dense[idx] = value;
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
else if (idx <= dense.size() + DENSE_GROW_THRESHOLD)
|
|
189
|
+
{
|
|
190
|
+
dense.resize(idx + 1, Constants::UNINITIALIZED);
|
|
191
|
+
dense[idx] = value;
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
{
|
|
196
|
+
sparse[idx] = value;
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
209
199
|
}
|