@ugo-studio/jspp 0.2.8 → 0.2.9
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 +2 -2
- 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 +42 -22
- package/package.json +1 -1
- package/scripts/precompile-headers.ts +13 -5
- package/src/prelude/any_value.hpp +26 -25
- package/src/prelude/any_value_access.hpp +7 -7
- package/src/prelude/any_value_defines.hpp +17 -17
- package/src/prelude/any_value_helpers.hpp +16 -7
- package/src/prelude/library/array.hpp +7 -7
- package/src/prelude/library/console.hpp +5 -5
- package/src/prelude/library/error.hpp +3 -3
- package/src/prelude/library/function.hpp +1 -1
- package/src/prelude/library/math.hpp +38 -38
- package/src/prelude/library/object.hpp +16 -16
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +1 -1
- package/src/prelude/library/promise.hpp +8 -8
- package/src/prelude/library/symbol.hpp +3 -3
- package/src/prelude/library/timer.hpp +4 -4
- package/src/prelude/types.hpp +4 -4
- package/src/prelude/utils/access.hpp +24 -6
- package/src/prelude/utils/operators.hpp +7 -0
- package/src/prelude/values/async_iterator.hpp +5 -3
- package/src/prelude/values/function.hpp +3 -3
- package/src/prelude/values/helpers/async_iterator.hpp +7 -3
- package/src/prelude/values/helpers/function.hpp +10 -10
- package/src/prelude/values/helpers/iterator.hpp +39 -2
- package/src/prelude/values/helpers/promise.hpp +9 -9
- package/src/prelude/values/helpers/string.hpp +17 -3
- package/src/prelude/values/iterator.hpp +32 -5
- package/src/prelude/values/promise.hpp +7 -7
- package/src/prelude/values/prototypes/array.hpp +41 -41
- package/src/prelude/values/prototypes/iterator.hpp +128 -1
|
@@ -3,7 +3,10 @@ import fs from "fs/promises";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
const PRELUDE_DIR = path.resolve(process.cwd(), "src", "prelude");
|
|
6
|
-
const PRECOMPILED_HEADER_BASE_DIR = path.resolve(
|
|
6
|
+
const PRECOMPILED_HEADER_BASE_DIR = path.resolve(
|
|
7
|
+
process.cwd(),
|
|
8
|
+
"prelude-build",
|
|
9
|
+
);
|
|
7
10
|
|
|
8
11
|
const MODES = [
|
|
9
12
|
{
|
|
@@ -52,7 +55,9 @@ async function precompileHeaders() {
|
|
|
52
55
|
try {
|
|
53
56
|
const gchStats = await fs.stat(gchPath);
|
|
54
57
|
if (gchStats.mtimeMs >= sourceMtime) {
|
|
55
|
-
console.log(
|
|
58
|
+
console.log(
|
|
59
|
+
`[${mode.name.toUpperCase()}] Headers are up-to-date. Skipping.`,
|
|
60
|
+
);
|
|
56
61
|
continue;
|
|
57
62
|
}
|
|
58
63
|
} catch (e) {
|
|
@@ -78,7 +83,7 @@ async function precompileHeaders() {
|
|
|
78
83
|
|
|
79
84
|
console.log(`[${mode.name.toUpperCase()}] Compiling header...`);
|
|
80
85
|
const tempGchPath = `${gchPath}.tmp`;
|
|
81
|
-
|
|
86
|
+
|
|
82
87
|
const compile = spawnSync(
|
|
83
88
|
"g++",
|
|
84
89
|
[
|
|
@@ -94,12 +99,14 @@ async function precompileHeaders() {
|
|
|
94
99
|
],
|
|
95
100
|
{
|
|
96
101
|
stdio: "inherit",
|
|
97
|
-
}
|
|
102
|
+
},
|
|
98
103
|
);
|
|
99
104
|
|
|
100
105
|
if (compile.status !== 0) {
|
|
101
|
-
|
|
106
|
+
try {
|
|
102
107
|
await fs.unlink(tempGchPath);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
// Ignore if temp file doesn't exist
|
|
103
110
|
}
|
|
104
111
|
console.error(
|
|
105
112
|
`[${mode.name.toUpperCase()}] Failed to precompile headers.`,
|
|
@@ -107,6 +114,7 @@ async function precompileHeaders() {
|
|
|
107
114
|
process.exit(1);
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
// Atomically replace the old GCH with the new one
|
|
110
118
|
await fs.rename(tempGchPath, gchPath);
|
|
111
119
|
console.log(`[${mode.name.toUpperCase()}] Success.`);
|
|
112
120
|
}
|
|
@@ -201,8 +201,8 @@ namespace jspp
|
|
|
201
201
|
static AnyValue make_symbol(const std::string &description = "") noexcept;
|
|
202
202
|
static AnyValue make_promise(const JsPromise &promise) noexcept;
|
|
203
203
|
static AnyValue make_data_descriptor(AnyValue value, bool writable, bool enumerable, bool configurable) noexcept;
|
|
204
|
-
static AnyValue make_accessor_descriptor(const std::optional<std::function<AnyValue(
|
|
205
|
-
const std::optional<std::function<AnyValue(
|
|
204
|
+
static AnyValue make_accessor_descriptor(const std::optional<std::function<AnyValue(AnyValue, std::span<const AnyValue>)>> &get,
|
|
205
|
+
const std::optional<std::function<AnyValue(AnyValue, std::span<const AnyValue>)>> &set,
|
|
206
206
|
bool enumerable,
|
|
207
207
|
bool configurable) noexcept;
|
|
208
208
|
|
|
@@ -222,8 +222,8 @@ namespace jspp
|
|
|
222
222
|
return v;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
static AnyValue resolve_property_for_read(const AnyValue &val,
|
|
226
|
-
static AnyValue resolve_property_for_write(AnyValue &val,
|
|
225
|
+
static AnyValue resolve_property_for_read(const AnyValue &val, AnyValue thisVal, const std::string &propName) noexcept;
|
|
226
|
+
static AnyValue resolve_property_for_write(AnyValue &val, AnyValue thisVal, const AnyValue &new_val, const std::string &propName);
|
|
227
227
|
|
|
228
228
|
// TYPE CHECKERS AND ACCESSORS ---------------------------------------
|
|
229
229
|
inline JsType get_type() const noexcept
|
|
@@ -295,14 +295,14 @@ namespace jspp
|
|
|
295
295
|
AnyValue get_own_property(int idx) const { return get_own_property(static_cast<uint32_t>(idx)); }
|
|
296
296
|
AnyValue get_own_property(const AnyValue &key) const;
|
|
297
297
|
|
|
298
|
-
AnyValue get_property_with_receiver(const std::string &key,
|
|
299
|
-
AnyValue get_property_with_receiver(const char *key,
|
|
298
|
+
AnyValue get_property_with_receiver(const std::string &key, AnyValue receiver) const;
|
|
299
|
+
AnyValue get_property_with_receiver(const char *key, AnyValue receiver) const { return get_property_with_receiver(std::string(key), receiver); }
|
|
300
300
|
|
|
301
|
-
AnyValue set_own_property(const std::string &key,
|
|
302
|
-
AnyValue set_own_property(const char *key,
|
|
303
|
-
AnyValue set_own_property(uint32_t idx,
|
|
304
|
-
AnyValue set_own_property(int idx,
|
|
305
|
-
AnyValue set_own_property(const AnyValue &key,
|
|
301
|
+
AnyValue set_own_property(const std::string &key, AnyValue value) const;
|
|
302
|
+
AnyValue set_own_property(const char *key, AnyValue value) const { return set_own_property(std::string(key), value); }
|
|
303
|
+
AnyValue set_own_property(uint32_t idx, AnyValue value) const;
|
|
304
|
+
AnyValue set_own_property(int idx, AnyValue value) const { return set_own_property(static_cast<uint32_t>(idx), value); }
|
|
305
|
+
AnyValue set_own_property(const AnyValue &key, AnyValue value) const;
|
|
306
306
|
|
|
307
307
|
AnyValue call_own_property(const std::string &key, std::span<const AnyValue> args) const;
|
|
308
308
|
AnyValue call_own_property(const char *key, std::span<const AnyValue> args) const { return call_own_property(std::string(key), args); }
|
|
@@ -310,25 +310,26 @@ namespace jspp
|
|
|
310
310
|
AnyValue call_own_property(int idx, std::span<const AnyValue> args) const { return call_own_property(static_cast<uint32_t>(idx), args); }
|
|
311
311
|
AnyValue call_own_property(const AnyValue &key, std::span<const AnyValue> args) const;
|
|
312
312
|
|
|
313
|
-
void define_data_property(const std::string &key,
|
|
314
|
-
void define_data_property(const char *key,
|
|
315
|
-
void define_data_property(const AnyValue &key,
|
|
316
|
-
void define_data_property(const std::string &key,
|
|
317
|
-
void define_data_property(const char *key,
|
|
313
|
+
void define_data_property(const std::string &key, AnyValue value);
|
|
314
|
+
void define_data_property(const char *key, AnyValue value) { define_data_property(std::string(key), value); }
|
|
315
|
+
void define_data_property(const AnyValue &key, AnyValue value);
|
|
316
|
+
void define_data_property(const std::string &key, AnyValue value, bool writable, bool enumerable, bool configurable);
|
|
317
|
+
void define_data_property(const char *key, AnyValue value, bool writable, bool enumerable, bool configurable) { define_data_property(std::string(key), value, writable, enumerable, configurable); }
|
|
318
318
|
|
|
319
|
-
void define_getter(const std::string &key,
|
|
320
|
-
void define_getter(const char *key,
|
|
321
|
-
void define_getter(const AnyValue &key,
|
|
319
|
+
void define_getter(const std::string &key, AnyValue getter);
|
|
320
|
+
void define_getter(const char *key, AnyValue getter) { define_getter(std::string(key), getter); }
|
|
321
|
+
void define_getter(const AnyValue &key, AnyValue getter);
|
|
322
322
|
|
|
323
|
-
void define_setter(const std::string &key,
|
|
324
|
-
void define_setter(const char *key,
|
|
325
|
-
void define_setter(const AnyValue &key,
|
|
323
|
+
void define_setter(const std::string &key, AnyValue setter);
|
|
324
|
+
void define_setter(const char *key, AnyValue setter) { define_setter(std::string(key), setter); }
|
|
325
|
+
void define_setter(const AnyValue &key, AnyValue setter);
|
|
326
326
|
|
|
327
|
-
AnyValue call(
|
|
328
|
-
AnyValue optional_call(
|
|
327
|
+
AnyValue call(AnyValue thisVal, std::span<const AnyValue> args, const std::optional<std::string> &expr = std::nullopt) const;
|
|
328
|
+
AnyValue optional_call(AnyValue thisVal, std::span<const AnyValue> args, const std::optional<std::string> &expr = std::nullopt) const;
|
|
329
329
|
AnyValue construct(std::span<const AnyValue> args, const std::optional<std::string> &name = std::nullopt) const;
|
|
330
|
-
void set_prototype(
|
|
330
|
+
void set_prototype(AnyValue proto);
|
|
331
331
|
std::string to_std_string() const;
|
|
332
|
+
std::string to_property_key() const;
|
|
332
333
|
|
|
333
334
|
inline uint64_t get_storage() const noexcept { return storage; }
|
|
334
335
|
inline void *get_raw_ptr() const noexcept { return reinterpret_cast<void *>(storage & PAYLOAD_MASK); }
|
|
@@ -26,7 +26,7 @@ namespace jspp
|
|
|
26
26
|
case JsType::AsyncIterator:
|
|
27
27
|
return false;
|
|
28
28
|
case JsType::Symbol:
|
|
29
|
-
return
|
|
29
|
+
return SymbolPrototypes::get(key).has_value();
|
|
30
30
|
case JsType::String:
|
|
31
31
|
if (key == "length")
|
|
32
32
|
return true;
|
|
@@ -35,9 +35,9 @@ namespace jspp
|
|
|
35
35
|
uint32_t idx = static_cast<uint32_t>(std::stoull(key));
|
|
36
36
|
return idx < as_string()->value.length();
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return StringPrototypes::get(key).has_value();
|
|
39
39
|
case JsType::Number:
|
|
40
|
-
return
|
|
40
|
+
return NumberPrototypes::get(key).has_value();
|
|
41
41
|
case JsType::Uninitialized:
|
|
42
42
|
Exception::throw_uninitialized_reference("#<Object>");
|
|
43
43
|
return false;
|
|
@@ -64,7 +64,7 @@ namespace jspp
|
|
|
64
64
|
return get_own_property(key.to_std_string());
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
inline AnyValue AnyValue::get_property_with_receiver(const std::string &key,
|
|
67
|
+
inline AnyValue AnyValue::get_property_with_receiver(const std::string &key, AnyValue receiver) const
|
|
68
68
|
{
|
|
69
69
|
switch (get_type())
|
|
70
70
|
{
|
|
@@ -104,7 +104,7 @@ namespace jspp
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
inline AnyValue AnyValue::set_own_property(const std::string &key,
|
|
107
|
+
inline AnyValue AnyValue::set_own_property(const std::string &key, AnyValue value) const
|
|
108
108
|
{
|
|
109
109
|
switch (get_type())
|
|
110
110
|
{
|
|
@@ -124,7 +124,7 @@ namespace jspp
|
|
|
124
124
|
return value;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
inline AnyValue AnyValue::set_own_property(uint32_t idx,
|
|
127
|
+
inline AnyValue AnyValue::set_own_property(uint32_t idx, AnyValue value) const
|
|
128
128
|
{
|
|
129
129
|
if (is_array())
|
|
130
130
|
{
|
|
@@ -132,7 +132,7 @@ namespace jspp
|
|
|
132
132
|
}
|
|
133
133
|
return set_own_property(std::to_string(idx), value);
|
|
134
134
|
}
|
|
135
|
-
inline AnyValue AnyValue::set_own_property(const AnyValue &key,
|
|
135
|
+
inline AnyValue AnyValue::set_own_property(const AnyValue &key, AnyValue value) const
|
|
136
136
|
{
|
|
137
137
|
if (key.is_number() && is_array())
|
|
138
138
|
{
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
namespace jspp
|
|
9
9
|
{
|
|
10
|
-
inline void AnyValue::define_data_property(const std::string &key,
|
|
10
|
+
inline void AnyValue::define_data_property(const std::string &key, AnyValue value)
|
|
11
11
|
{
|
|
12
12
|
if (is_object())
|
|
13
13
|
{
|
|
@@ -29,7 +29,7 @@ namespace jspp
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
inline void AnyValue::define_data_property(const AnyValue &key,
|
|
32
|
+
inline void AnyValue::define_data_property(const AnyValue &key, AnyValue value)
|
|
33
33
|
{
|
|
34
34
|
if (key.is_symbol())
|
|
35
35
|
define_data_property(key.as_symbol()->key, value);
|
|
@@ -37,12 +37,12 @@ namespace jspp
|
|
|
37
37
|
define_data_property(key.to_std_string(), value);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
inline void AnyValue::define_data_property(const std::string &key,
|
|
40
|
+
inline void AnyValue::define_data_property(const std::string &key, AnyValue value, bool writable, bool enumerable, bool configurable)
|
|
41
41
|
{
|
|
42
42
|
define_data_property(key, AnyValue::make_data_descriptor(value, writable, enumerable, configurable));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
inline void AnyValue::define_getter(const std::string &key,
|
|
45
|
+
inline void AnyValue::define_getter(const std::string &key, AnyValue getter)
|
|
46
46
|
{
|
|
47
47
|
if (is_object())
|
|
48
48
|
{
|
|
@@ -55,14 +55,14 @@ namespace jspp
|
|
|
55
55
|
if (val.is_accessor_descriptor())
|
|
56
56
|
{
|
|
57
57
|
auto desc = val.as_accessor_descriptor();
|
|
58
|
-
desc->get = [getter](
|
|
58
|
+
desc->get = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
59
59
|
{
|
|
60
60
|
return getter.call(thisVal, args);
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
else
|
|
64
64
|
{
|
|
65
|
-
auto getFunc = [getter](
|
|
65
|
+
auto getFunc = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
66
66
|
{
|
|
67
67
|
return getter.call(thisVal, args);
|
|
68
68
|
};
|
|
@@ -71,7 +71,7 @@ namespace jspp
|
|
|
71
71
|
}
|
|
72
72
|
else
|
|
73
73
|
{
|
|
74
|
-
auto getFunc = [getter](
|
|
74
|
+
auto getFunc = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
75
75
|
{
|
|
76
76
|
return getter.call(thisVal, args);
|
|
77
77
|
};
|
|
@@ -86,14 +86,14 @@ namespace jspp
|
|
|
86
86
|
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
87
87
|
{
|
|
88
88
|
auto desc = it->second.as_accessor_descriptor();
|
|
89
|
-
desc->get = [getter](
|
|
89
|
+
desc->get = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
90
90
|
{
|
|
91
91
|
return getter.call(thisVal, args);
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
else
|
|
95
95
|
{
|
|
96
|
-
auto getFunc = [getter](
|
|
96
|
+
auto getFunc = [getter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
97
97
|
{
|
|
98
98
|
return getter.call(thisVal, args);
|
|
99
99
|
};
|
|
@@ -102,7 +102,7 @@ namespace jspp
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
inline void AnyValue::define_getter(const AnyValue &key,
|
|
105
|
+
inline void AnyValue::define_getter(const AnyValue &key, AnyValue getter)
|
|
106
106
|
{
|
|
107
107
|
if (key.is_symbol())
|
|
108
108
|
define_getter(key.as_symbol()->key, getter);
|
|
@@ -110,7 +110,7 @@ namespace jspp
|
|
|
110
110
|
define_getter(key.to_std_string(), getter);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
inline void AnyValue::define_setter(const std::string &key,
|
|
113
|
+
inline void AnyValue::define_setter(const std::string &key, AnyValue setter)
|
|
114
114
|
{
|
|
115
115
|
if (is_object())
|
|
116
116
|
{
|
|
@@ -123,7 +123,7 @@ namespace jspp
|
|
|
123
123
|
if (val.is_accessor_descriptor())
|
|
124
124
|
{
|
|
125
125
|
auto desc = val.as_accessor_descriptor();
|
|
126
|
-
desc->set = [setter](
|
|
126
|
+
desc->set = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
127
127
|
{
|
|
128
128
|
if (args.empty())
|
|
129
129
|
return Constants::UNDEFINED;
|
|
@@ -132,7 +132,7 @@ namespace jspp
|
|
|
132
132
|
}
|
|
133
133
|
else
|
|
134
134
|
{
|
|
135
|
-
auto setFunc = [setter](
|
|
135
|
+
auto setFunc = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
136
136
|
{
|
|
137
137
|
if (args.empty())
|
|
138
138
|
return Constants::UNDEFINED;
|
|
@@ -143,7 +143,7 @@ namespace jspp
|
|
|
143
143
|
}
|
|
144
144
|
else
|
|
145
145
|
{
|
|
146
|
-
auto setFunc = [setter](
|
|
146
|
+
auto setFunc = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
147
147
|
{
|
|
148
148
|
if (args.empty())
|
|
149
149
|
return Constants::UNDEFINED;
|
|
@@ -160,7 +160,7 @@ namespace jspp
|
|
|
160
160
|
if (it != props.end() && it->second.is_accessor_descriptor())
|
|
161
161
|
{
|
|
162
162
|
auto desc = it->second.as_accessor_descriptor();
|
|
163
|
-
desc->set = [setter](
|
|
163
|
+
desc->set = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
164
164
|
{
|
|
165
165
|
if (args.empty())
|
|
166
166
|
return Constants::UNDEFINED;
|
|
@@ -169,7 +169,7 @@ namespace jspp
|
|
|
169
169
|
}
|
|
170
170
|
else
|
|
171
171
|
{
|
|
172
|
-
auto setFunc = [setter](
|
|
172
|
+
auto setFunc = [setter](AnyValue thisVal, std::span<const AnyValue> args) -> AnyValue
|
|
173
173
|
{
|
|
174
174
|
if (args.empty())
|
|
175
175
|
return Constants::UNDEFINED;
|
|
@@ -180,7 +180,7 @@ namespace jspp
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
inline void AnyValue::define_setter(const AnyValue &key,
|
|
183
|
+
inline void AnyValue::define_setter(const AnyValue &key, AnyValue setter)
|
|
184
184
|
{
|
|
185
185
|
if (key.is_symbol())
|
|
186
186
|
define_setter(key.as_symbol()->key, setter);
|
|
@@ -142,8 +142,8 @@ namespace jspp
|
|
|
142
142
|
{
|
|
143
143
|
return from_ptr(new DataDescriptor(value, writable, enumerable, configurable));
|
|
144
144
|
}
|
|
145
|
-
inline AnyValue AnyValue::make_accessor_descriptor(const std::optional<std::function<AnyValue(
|
|
146
|
-
const std::optional<std::function<AnyValue(
|
|
145
|
+
inline AnyValue AnyValue::make_accessor_descriptor(const std::optional<std::function<AnyValue(AnyValue, std::span<const AnyValue>)>> &get,
|
|
146
|
+
const std::optional<std::function<AnyValue(AnyValue, std::span<const AnyValue>)>> &set,
|
|
147
147
|
bool enumerable,
|
|
148
148
|
bool configurable) noexcept
|
|
149
149
|
{
|
|
@@ -180,7 +180,7 @@ namespace jspp
|
|
|
180
180
|
return from_ptr(it);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
inline AnyValue AnyValue::resolve_property_for_read(const AnyValue &val,
|
|
183
|
+
inline AnyValue AnyValue::resolve_property_for_read(const AnyValue &val, AnyValue thisVal, const std::string &propName) noexcept
|
|
184
184
|
{
|
|
185
185
|
if (val.is_data_descriptor())
|
|
186
186
|
{
|
|
@@ -198,7 +198,7 @@ namespace jspp
|
|
|
198
198
|
}
|
|
199
199
|
return val;
|
|
200
200
|
}
|
|
201
|
-
inline AnyValue AnyValue::resolve_property_for_write(AnyValue &val,
|
|
201
|
+
inline AnyValue AnyValue::resolve_property_for_write(AnyValue &val, AnyValue thisVal, const AnyValue &new_val, const std::string &propName)
|
|
202
202
|
{
|
|
203
203
|
if (val.is_data_descriptor())
|
|
204
204
|
{
|
|
@@ -299,7 +299,16 @@ namespace jspp
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
inline
|
|
302
|
+
inline std::string AnyValue::to_property_key() const
|
|
303
|
+
{
|
|
304
|
+
if (is_symbol())
|
|
305
|
+
{
|
|
306
|
+
return as_symbol()->key;
|
|
307
|
+
}
|
|
308
|
+
return to_std_string();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
inline void AnyValue::set_prototype(AnyValue proto)
|
|
303
312
|
{
|
|
304
313
|
if (is_object())
|
|
305
314
|
{
|
|
@@ -320,13 +329,13 @@ namespace jspp
|
|
|
320
329
|
}
|
|
321
330
|
|
|
322
331
|
// AnyValue::call implementation
|
|
323
|
-
inline AnyValue AnyValue::call(
|
|
332
|
+
inline AnyValue AnyValue::call(AnyValue thisVal, std::span<const AnyValue> args, const std::optional<std::string> &expr) const
|
|
324
333
|
{
|
|
325
334
|
if (!is_function())
|
|
326
335
|
throw Exception::make_exception(expr.value_or(to_std_string()) + " is not a function", "TypeError");
|
|
327
336
|
return as_function()->call(thisVal, args);
|
|
328
337
|
}
|
|
329
|
-
inline AnyValue AnyValue::optional_call(
|
|
338
|
+
inline AnyValue AnyValue::optional_call(AnyValue thisVal, std::span<const AnyValue> args, const std::optional<std::string> &expr) const
|
|
330
339
|
{
|
|
331
340
|
if (is_null() || is_undefined())
|
|
332
341
|
return Constants::UNDEFINED;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
#include "utils/operators.hpp"
|
|
6
6
|
#include "utils/access.hpp"
|
|
7
7
|
|
|
8
|
-
inline auto Array = jspp::AnyValue::make_class([](
|
|
8
|
+
inline auto Array = jspp::AnyValue::make_class([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
9
9
|
{
|
|
10
10
|
if (args.size() == 1 && args[0].is_number()) {
|
|
11
11
|
double len = args[0].as_double();
|
|
@@ -29,13 +29,13 @@ struct ArrayInit
|
|
|
29
29
|
ArrayInit()
|
|
30
30
|
{
|
|
31
31
|
// Array.isArray(value)
|
|
32
|
-
Array.define_data_property("isArray", jspp::AnyValue::make_function([](
|
|
32
|
+
Array.define_data_property("isArray", jspp::AnyValue::make_function([](jspp::AnyValue, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
33
33
|
{
|
|
34
34
|
if (args.empty()) return jspp::Constants::FALSE;
|
|
35
35
|
return jspp::AnyValue::make_boolean(args[0].is_array()); }, "isArray"));
|
|
36
36
|
|
|
37
37
|
// Array.of(...elements)
|
|
38
|
-
Array.define_data_property("of", jspp::AnyValue::make_function([](
|
|
38
|
+
Array.define_data_property("of", jspp::AnyValue::make_function([](jspp::AnyValue, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
39
39
|
{
|
|
40
40
|
std::vector<jspp::AnyValue> elements;
|
|
41
41
|
for(const auto& arg : args) {
|
|
@@ -44,7 +44,7 @@ struct ArrayInit
|
|
|
44
44
|
return jspp::AnyValue::make_array(std::move(elements)); }, "of"));
|
|
45
45
|
|
|
46
46
|
// Array.from(arrayLike, mapFn?, thisArg?)
|
|
47
|
-
Array.define_data_property("from", jspp::AnyValue::make_function([](
|
|
47
|
+
Array.define_data_property("from", jspp::AnyValue::make_function([](jspp::AnyValue, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
48
48
|
{
|
|
49
49
|
if (args.empty() || args[0].is_null() || args[0].is_undefined()) {
|
|
50
50
|
throw jspp::Exception::make_exception("Array.from requires an array-like object", "TypeError");
|
|
@@ -58,7 +58,7 @@ struct ArrayInit
|
|
|
58
58
|
|
|
59
59
|
auto iteratorSym = jspp::WellKnownSymbols::iterator;
|
|
60
60
|
if (items.has_property(iteratorSym->key)) {
|
|
61
|
-
auto iter = jspp::Access::
|
|
61
|
+
auto iter = jspp::Access::get_object_iterator(items, "Array.from source");
|
|
62
62
|
auto nextFn = iter.get_own_property("next");
|
|
63
63
|
|
|
64
64
|
size_t k = 0;
|
|
@@ -94,7 +94,7 @@ struct ArrayInit
|
|
|
94
94
|
return jspp::AnyValue::make_array(std::move(result)); }, "from"));
|
|
95
95
|
|
|
96
96
|
// Array.fromAsync(iterableOrArrayLike, mapFn?, thisArg?)
|
|
97
|
-
Array.define_data_property("fromAsync", jspp::AnyValue::make_async_function([](
|
|
97
|
+
Array.define_data_property("fromAsync", jspp::AnyValue::make_async_function([](jspp::AnyValue, std::vector<jspp::AnyValue> args) -> jspp::JsPromise
|
|
98
98
|
{
|
|
99
99
|
if (args.empty() || args[0].is_null() || args[0].is_undefined()) {
|
|
100
100
|
throw jspp::Exception::make_exception("Array.fromAsync requires an iterable or array-like object", "TypeError");
|
|
@@ -180,7 +180,7 @@ struct ArrayInit
|
|
|
180
180
|
co_return jspp::AnyValue::make_array(std::move(result)); }, "fromAsync"));
|
|
181
181
|
|
|
182
182
|
// Array[Symbol.species]
|
|
183
|
-
Array.define_getter(jspp::AnyValue::from_symbol(jspp::WellKnownSymbols::species), jspp::AnyValue::make_function([](
|
|
183
|
+
Array.define_getter(jspp::AnyValue::from_symbol(jspp::WellKnownSymbols::species), jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
184
184
|
{ return thisVal; }, "get [Symbol.species]"));
|
|
185
185
|
}
|
|
186
186
|
} arrayInit;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
static std::map<std::string, std::chrono::steady_clock::time_point> timers = {};
|
|
17
17
|
|
|
18
|
-
auto logFn = jspp::AnyValue::make_function([](
|
|
18
|
+
auto logFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args)
|
|
19
19
|
{
|
|
20
20
|
for (size_t i = 0; i < args.size(); ++i)
|
|
21
21
|
{
|
|
@@ -25,7 +25,7 @@ auto logFn = jspp::AnyValue::make_function([](const jspp::AnyValue &thisVal, std
|
|
|
25
25
|
}
|
|
26
26
|
std::cout << "\n" << std::flush;
|
|
27
27
|
return jspp::Constants::UNDEFINED; }, "log");
|
|
28
|
-
auto warnFn = jspp::AnyValue::make_function([](
|
|
28
|
+
auto warnFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args)
|
|
29
29
|
{
|
|
30
30
|
std::cerr << "\033[33m";
|
|
31
31
|
for (size_t i = 0; i < args.size(); ++i)
|
|
@@ -36,7 +36,7 @@ auto warnFn = jspp::AnyValue::make_function([](const jspp::AnyValue &thisVal, st
|
|
|
36
36
|
}
|
|
37
37
|
std::cerr << "\033[0m" << "\n" << std::flush; // reset
|
|
38
38
|
return jspp::Constants::UNDEFINED; }, "warn");
|
|
39
|
-
auto errorFn = jspp::AnyValue::make_function([](
|
|
39
|
+
auto errorFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args)
|
|
40
40
|
{
|
|
41
41
|
std::cerr << "\033[31m";
|
|
42
42
|
for (size_t i = 0; i < args.size(); ++i)
|
|
@@ -47,7 +47,7 @@ auto errorFn = jspp::AnyValue::make_function([](const jspp::AnyValue &thisVal, s
|
|
|
47
47
|
}
|
|
48
48
|
std::cerr << "\033[0m" << "\n" << std::flush; // reset
|
|
49
49
|
return jspp::Constants::UNDEFINED; }, "error");
|
|
50
|
-
auto timeFn = jspp::AnyValue::make_function([](
|
|
50
|
+
auto timeFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args)
|
|
51
51
|
{
|
|
52
52
|
auto start = std::chrono::steady_clock::now(); // capture immediately
|
|
53
53
|
auto key_str = args.size() > 0 ? args[0].to_std_string() : "default";
|
|
@@ -84,7 +84,7 @@ static auto format_duration = [](double ms) -> std::string
|
|
|
84
84
|
return ss.str();
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
auto timeEndFn = jspp::AnyValue::make_function([](
|
|
87
|
+
auto timeEndFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args)
|
|
88
88
|
{
|
|
89
89
|
auto end = std::chrono::steady_clock::now(); // capture immediately
|
|
90
90
|
auto key_str = args.size() > 0 ? args[0].to_std_string() : "default";
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
inline jspp::AnyValue Error;
|
|
8
8
|
|
|
9
9
|
// Constructor logic
|
|
10
|
-
inline auto errorConstructor = [](
|
|
10
|
+
inline auto errorConstructor = [](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
11
11
|
{
|
|
12
12
|
// Access global Error to get prototype
|
|
13
13
|
jspp::AnyValue proto = Error.get_own_property("prototype");
|
|
@@ -53,7 +53,7 @@ inline auto errorConstructor = [](const jspp::AnyValue &thisVal, std::span<const
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
// Static Error.isError(val) implementation
|
|
56
|
-
inline auto isErrorFn = jspp::AnyValue::make_function([](
|
|
56
|
+
inline auto isErrorFn = jspp::AnyValue::make_function([](jspp::AnyValue, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
57
57
|
{
|
|
58
58
|
if (args.empty()) return jspp::Constants::FALSE;
|
|
59
59
|
|
|
@@ -77,7 +77,7 @@ inline auto isErrorFn = jspp::AnyValue::make_function([](const jspp::AnyValue &t
|
|
|
77
77
|
return jspp::Constants::FALSE; }, "isError");
|
|
78
78
|
|
|
79
79
|
// toString method for Error.prototype
|
|
80
|
-
inline auto errorToStringFn = jspp::AnyValue::make_function([](
|
|
80
|
+
inline auto errorToStringFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
81
81
|
{
|
|
82
82
|
std::string name = "Error";
|
|
83
83
|
std::string msg = "";
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
// Define Function constructor
|
|
7
7
|
// In a full implementation, this would support 'new Function(args, body)'
|
|
8
|
-
inline auto Function = jspp::AnyValue::make_class([](
|
|
8
|
+
inline auto Function = jspp::AnyValue::make_class([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue {
|
|
9
9
|
return jspp::Constants::UNDEFINED;
|
|
10
10
|
}, "Function");
|