@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,170 +1,170 @@
|
|
|
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
|
|
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
|
|
39
|
-
case JsType::Number:
|
|
40
|
-
return
|
|
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,
|
|
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);
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
}
|
|
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 SymbolPrototypes::get(key).has_value();
|
|
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 StringPrototypes::get(key).has_value();
|
|
39
|
+
case JsType::Number:
|
|
40
|
+
return NumberPrototypes::get(key).has_value();
|
|
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, 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);
|
|
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, 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, 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, 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
|
+
}
|