@ugo-studio/jspp 0.3.0 → 0.3.2

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.
Files changed (127) hide show
  1. package/LICENSE +25 -25
  2. package/README.md +20 -12
  3. package/dist/cli/args.js +22 -0
  4. package/dist/cli/compiler.js +53 -0
  5. package/dist/cli/index.js +43 -107
  6. package/dist/cli/pch.js +71 -0
  7. package/dist/cli/runner.js +23 -0
  8. package/dist/cli/spinner.js +27 -11
  9. package/dist/cli/transpiler.js +20 -0
  10. package/dist/cli/utils.js +59 -0
  11. package/dist/cli/wasm.js +70 -0
  12. package/dist/index.js +17 -6
  13. package/dist/{analysis → interpreter/analysis}/scope.js +38 -3
  14. package/dist/{analysis → interpreter/analysis}/typeAnalyzer.js +563 -28
  15. package/dist/{core → interpreter/core}/codegen/class-handlers.js +1 -1
  16. package/dist/{core → interpreter/core}/codegen/control-flow-handlers.js +12 -11
  17. package/dist/{core → interpreter/core}/codegen/declaration-handlers.js +28 -9
  18. package/dist/{core → interpreter/core}/codegen/destructuring-handlers.js +9 -4
  19. package/dist/{core → interpreter/core}/codegen/expression-handlers.js +82 -88
  20. package/dist/{core → interpreter/core}/codegen/function-handlers.js +159 -46
  21. package/dist/{core → interpreter/core}/codegen/helpers.js +170 -25
  22. package/dist/interpreter/core/codegen/index.js +156 -0
  23. package/dist/{core → interpreter/core}/codegen/literal-handlers.js +9 -0
  24. package/dist/{core → interpreter/core}/codegen/statement-handlers.js +47 -7
  25. package/package.json +6 -4
  26. package/scripts/precompile-headers.ts +293 -50
  27. package/scripts/setup-compiler.ts +63 -63
  28. package/scripts/setup-emsdk.ts +114 -0
  29. package/src/prelude/any_value.cpp +888 -0
  30. package/src/prelude/any_value.hpp +29 -24
  31. package/src/prelude/{exception_helpers.hpp → exception.cpp} +53 -53
  32. package/src/prelude/exception.hpp +27 -27
  33. package/src/prelude/iterator_instantiations.hpp +10 -0
  34. package/src/prelude/{index.hpp → jspp.hpp} +13 -17
  35. package/src/prelude/library/array.cpp +191 -0
  36. package/src/prelude/library/array.hpp +5 -178
  37. package/src/prelude/library/boolean.cpp +30 -0
  38. package/src/prelude/library/boolean.hpp +14 -0
  39. package/src/prelude/library/console.cpp +125 -0
  40. package/src/prelude/library/console.hpp +9 -97
  41. package/src/prelude/library/error.cpp +100 -0
  42. package/src/prelude/library/error.hpp +8 -108
  43. package/src/prelude/library/function.cpp +69 -0
  44. package/src/prelude/library/function.hpp +6 -5
  45. package/src/prelude/library/global.cpp +98 -0
  46. package/src/prelude/library/global.hpp +12 -28
  47. package/src/prelude/library/global_usings.hpp +15 -0
  48. package/src/prelude/library/math.cpp +261 -0
  49. package/src/prelude/library/math.hpp +8 -288
  50. package/src/prelude/library/object.cpp +379 -0
  51. package/src/prelude/library/object.hpp +5 -267
  52. package/src/prelude/library/performance.cpp +21 -0
  53. package/src/prelude/library/performance.hpp +5 -20
  54. package/src/prelude/library/process.cpp +38 -0
  55. package/src/prelude/library/process.hpp +3 -31
  56. package/src/prelude/library/promise.cpp +131 -0
  57. package/src/prelude/library/promise.hpp +5 -116
  58. package/src/prelude/library/symbol.cpp +56 -0
  59. package/src/prelude/library/symbol.hpp +5 -46
  60. package/src/prelude/library/timer.cpp +88 -0
  61. package/src/prelude/library/timer.hpp +11 -87
  62. package/src/prelude/runtime.cpp +19 -0
  63. package/src/prelude/types.hpp +26 -20
  64. package/src/prelude/utils/access.hpp +123 -32
  65. package/src/prelude/utils/assignment_operators.hpp +119 -99
  66. package/src/prelude/utils/log_any_value/array.hpp +61 -40
  67. package/src/prelude/utils/log_any_value/function.hpp +39 -39
  68. package/src/prelude/utils/log_any_value/log_any_value.hpp +1 -1
  69. package/src/prelude/utils/log_any_value/object.hpp +60 -3
  70. package/src/prelude/utils/log_any_value/primitives.hpp +1 -1
  71. package/src/prelude/utils/operators.hpp +109 -94
  72. package/src/prelude/utils/operators_native.hpp +349 -0
  73. package/src/prelude/utils/well_known_symbols.hpp +24 -24
  74. package/src/prelude/values/array.cpp +1399 -0
  75. package/src/prelude/values/array.hpp +4 -0
  76. package/src/prelude/values/async_iterator.cpp +251 -0
  77. package/src/prelude/values/async_iterator.hpp +60 -32
  78. package/src/prelude/values/boolean.cpp +64 -0
  79. package/src/prelude/values/function.cpp +262 -0
  80. package/src/prelude/values/function.hpp +10 -30
  81. package/src/prelude/values/iterator.cpp +309 -0
  82. package/src/prelude/values/iterator.hpp +33 -64
  83. package/src/prelude/values/number.cpp +221 -0
  84. package/src/prelude/values/object.cpp +200 -0
  85. package/src/prelude/values/object.hpp +4 -0
  86. package/src/prelude/values/promise.cpp +479 -0
  87. package/src/prelude/values/promise.hpp +9 -2
  88. package/src/prelude/values/prototypes/array.hpp +46 -1348
  89. package/src/prelude/values/prototypes/async_iterator.hpp +19 -61
  90. package/src/prelude/values/prototypes/boolean.hpp +24 -0
  91. package/src/prelude/values/prototypes/function.hpp +7 -46
  92. package/src/prelude/values/prototypes/iterator.hpp +15 -191
  93. package/src/prelude/values/prototypes/number.hpp +30 -210
  94. package/src/prelude/values/prototypes/object.hpp +7 -23
  95. package/src/prelude/values/prototypes/promise.hpp +8 -186
  96. package/src/prelude/values/prototypes/string.hpp +28 -553
  97. package/src/prelude/values/prototypes/symbol.hpp +9 -70
  98. package/src/prelude/values/shape.hpp +52 -52
  99. package/src/prelude/values/string.cpp +485 -0
  100. package/src/prelude/values/symbol.cpp +89 -0
  101. package/src/prelude/values/symbol.hpp +101 -101
  102. package/dist/cli/file-utils.js +0 -20
  103. package/dist/cli-utils/args.js +0 -59
  104. package/dist/cli-utils/colors.js +0 -9
  105. package/dist/cli-utils/file-utils.js +0 -20
  106. package/dist/cli-utils/spinner.js +0 -55
  107. package/dist/cli.js +0 -153
  108. package/dist/core/codegen/index.js +0 -86
  109. package/src/prelude/any_value_access.hpp +0 -170
  110. package/src/prelude/any_value_defines.hpp +0 -190
  111. package/src/prelude/any_value_helpers.hpp +0 -374
  112. package/src/prelude/utils/operators_primitive.hpp +0 -337
  113. package/src/prelude/values/helpers/array.hpp +0 -199
  114. package/src/prelude/values/helpers/async_iterator.hpp +0 -275
  115. package/src/prelude/values/helpers/function.hpp +0 -109
  116. package/src/prelude/values/helpers/iterator.hpp +0 -145
  117. package/src/prelude/values/helpers/object.hpp +0 -104
  118. package/src/prelude/values/helpers/promise.hpp +0 -254
  119. package/src/prelude/values/helpers/string.hpp +0 -37
  120. package/src/prelude/values/helpers/symbol.hpp +0 -21
  121. /package/dist/{ast → interpreter/ast}/symbols.js +0 -0
  122. /package/dist/{ast → interpreter/ast}/types.js +0 -0
  123. /package/dist/{core → interpreter/core}/codegen/visitor.js +0 -0
  124. /package/dist/{core → interpreter/core}/constants.js +0 -0
  125. /package/dist/{core → interpreter/core}/error.js +0 -0
  126. /package/dist/{core → interpreter/core}/parser.js +0 -0
  127. /package/dist/{core → interpreter/core}/traverser.js +0 -0
@@ -13,6 +13,7 @@ namespace jspp
13
13
  std::vector<AnyValue> dense; // dense storage for small/contiguous indices
14
14
  std::unordered_map<uint32_t, AnyValue> sparse; // sparse indices (very large indices)
15
15
  std::unordered_map<std::string, AnyValue> props; // non-index string properties
16
+ std::map<AnyValue, AnyValue> symbol_props;
16
17
  AnyValue proto;
17
18
  uint64_t length = 0;
18
19
 
@@ -25,10 +26,13 @@ namespace jspp
25
26
  std::string to_std_string() const;
26
27
 
27
28
  bool has_property(const std::string &key) const;
29
+ bool has_symbol_property(const AnyValue &key) const;
28
30
  AnyValue get_property(const std::string &key, const AnyValue &thisVal);
29
31
  AnyValue get_property(uint32_t idx);
32
+ AnyValue get_symbol_property(const AnyValue &key, const AnyValue &thisVal);
30
33
  AnyValue set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal);
31
34
  AnyValue set_property(uint32_t idx, const AnyValue &value);
35
+ AnyValue set_symbol_property(const AnyValue &key, const AnyValue &value, const AnyValue &thisVal);
32
36
 
33
37
  static bool is_array_index(const std::string &s)
34
38
  {
@@ -0,0 +1,251 @@
1
+ #include "jspp.hpp"
2
+ #include "values/async_iterator.hpp"
3
+ #include "values/prototypes/async_iterator.hpp"
4
+
5
+ namespace jspp {
6
+
7
+ template <typename T>
8
+ JsAsyncIterator<T>::JsAsyncIterator(handle_type h) : handle(h) {}
9
+
10
+ template <typename T>
11
+ JsAsyncIterator<T>::JsAsyncIterator(JsAsyncIterator &&other) noexcept
12
+ : handle(std::exchange(other.handle, nullptr)),
13
+ props(std::move(other.props)),
14
+ symbol_props(std::move(other.symbol_props)) {}
15
+
16
+ template <typename T>
17
+ JsAsyncIterator<T>::~JsAsyncIterator() { if (handle) handle.destroy(); }
18
+
19
+ template <typename T>
20
+ JsAsyncIterator<T> JsAsyncIterator<T>::promise_type::get_return_object() {
21
+ return JsAsyncIterator{std::coroutine_handle<promise_type>::from_promise(*this)};
22
+ }
23
+
24
+ template <typename T>
25
+ std::suspend_always JsAsyncIterator<T>::promise_type::initial_suspend() noexcept { return {}; }
26
+
27
+ template <typename T>
28
+ std::suspend_always JsAsyncIterator<T>::promise_type::final_suspend() noexcept { return {}; }
29
+
30
+ template <typename T>
31
+ bool JsAsyncIterator<T>::promise_type::YieldAwaiter::await_ready() { return false; }
32
+
33
+ template <typename T>
34
+ void JsAsyncIterator<T>::promise_type::YieldAwaiter::await_suspend(std::coroutine_handle<promise_type> h) {}
35
+
36
+ template <typename T>
37
+ T JsAsyncIterator<T>::promise_type::YieldAwaiter::await_resume() { return p.current_input; }
38
+
39
+ template <typename T>
40
+ void JsAsyncIterator<T>::promise_type::unhandled_exception() {
41
+ try {
42
+ std::rethrow_exception(std::current_exception());
43
+ } catch (const Exception &e) {
44
+ fail_all(e.data);
45
+ } catch (const std::exception &e) {
46
+ fail_all(AnyValue::make_string(e.what()));
47
+ } catch (...) {
48
+ fail_all(AnyValue::make_string("Unknown error in async generator"));
49
+ }
50
+ }
51
+
52
+ template <typename T>
53
+ bool JsAsyncIterator<T>::promise_type::AsyncIterAwaiter::await_ready() { return base_awaiter.await_ready(); }
54
+
55
+ template <typename T>
56
+ void JsAsyncIterator<T>::promise_type::AsyncIterAwaiter::await_suspend(std::coroutine_handle<promise_type> h) {
57
+ if (!base_awaiter.value.is_promise()) {
58
+ jspp::Scheduler::instance().enqueue([h]() mutable {
59
+ auto &pr = h.promise();
60
+ pr.is_awaiting = false;
61
+ pr.is_running = true;
62
+ h.resume();
63
+ pr.is_running = false;
64
+ if (!h.done() && !pr.is_awaiting && !pr.pending_calls.empty()) {
65
+ while (!h.done() && !pr.is_awaiting && !pr.pending_calls.empty()) {
66
+ pr.is_running = true;
67
+ pr.current_input = pr.pending_calls.front().second;
68
+ h.resume();
69
+ pr.is_running = false;
70
+ }
71
+ }
72
+ });
73
+ return;
74
+ }
75
+ auto p = base_awaiter.value.as_promise();
76
+ p->then(
77
+ [h](AnyValue v) mutable {
78
+ auto &pr = h.promise();
79
+ pr.is_awaiting = false;
80
+ pr.is_running = true;
81
+ h.resume();
82
+ pr.is_running = false;
83
+ if (!h.done() && !pr.is_awaiting && !pr.pending_calls.empty()) {
84
+ while (!h.done() && !pr.is_awaiting && !pr.pending_calls.empty()) {
85
+ pr.is_running = true;
86
+ pr.current_input = pr.pending_calls.front().second;
87
+ h.resume();
88
+ pr.is_running = false;
89
+ }
90
+ }
91
+ },
92
+ [h](AnyValue e) mutable {
93
+ auto &pr = h.promise();
94
+ pr.is_awaiting = false;
95
+ pr.is_running = true;
96
+ h.resume();
97
+ pr.is_running = false;
98
+ }
99
+ );
100
+ }
101
+
102
+ template <typename T>
103
+ AnyValue JsAsyncIterator<T>::promise_type::AsyncIterAwaiter::await_resume() { return base_awaiter.await_resume(); }
104
+
105
+ template <typename T>
106
+ typename JsAsyncIterator<T>::promise_type::AsyncIterAwaiter JsAsyncIterator<T>::promise_type::await_transform(AnyValue value) {
107
+ is_awaiting = true;
108
+ return AsyncIterAwaiter{AnyValueAwaiter{std::move(value)}, *this};
109
+ }
110
+
111
+ template <typename T>
112
+ std::string JsAsyncIterator<T>::to_std_string() const { return "[object AsyncGenerator]"; }
113
+
114
+ template <typename T>
115
+ void JsAsyncIterator<T>::resume_next()
116
+ {
117
+ if (!handle || handle.done()) return;
118
+ auto &p = handle.promise();
119
+ if (p.is_awaiting || p.is_running) return;
120
+ if (p.pending_calls.empty()) return;
121
+ p.is_running = true;
122
+ auto &next_call = p.pending_calls.front();
123
+ p.current_input = next_call.second;
124
+ handle.resume();
125
+ p.is_running = false;
126
+ if (!p.pending_calls.empty() && !p.is_awaiting && !handle.done()) {
127
+ this->ref();
128
+ Scheduler::instance().enqueue([this]() { this->resume_next(); this->deref(); });
129
+ }
130
+ }
131
+
132
+ template <typename T>
133
+ JsPromise JsAsyncIterator<T>::next(const T &val)
134
+ {
135
+ JsPromise p;
136
+ if (handle) {
137
+ if (handle.done()) p.resolve(AnyValue::make_object({{"value", Constants::UNDEFINED}, {"done", Constants::TRUE}}));
138
+ else { handle.promise().pending_calls.push({p, val}); resume_next(); }
139
+ } else p.resolve(AnyValue::make_object({{"value", Constants::UNDEFINED}, {"done", Constants::TRUE}}));
140
+ return p;
141
+ }
142
+
143
+ template <typename T>
144
+ bool JsAsyncIterator<T>::has_symbol_property(const AnyValue &key) const { return symbol_props.count(key) > 0; }
145
+
146
+ template <typename T>
147
+ AnyValue JsAsyncIterator<T>::get_property(const std::string &key, AnyValue thisVal)
148
+ {
149
+ auto it = props.find(key);
150
+ if (it == props.end()) {
151
+ if constexpr (std::is_same_v<T, AnyValue>) {
152
+ auto proto_it = AsyncIteratorPrototypes::get(key);
153
+ if (proto_it.has_value()) return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key);
154
+ }
155
+ return Constants::UNDEFINED;
156
+ }
157
+ return AnyValue::resolve_property_for_read(it->second, thisVal, key);
158
+ }
159
+
160
+ template <typename T>
161
+ AnyValue JsAsyncIterator<T>::get_symbol_property(const AnyValue &key, AnyValue thisVal)
162
+ {
163
+ auto it = symbol_props.find(key);
164
+ if (it == symbol_props.end()) {
165
+ if constexpr (std::is_same_v<T, AnyValue>) {
166
+ auto proto_it = AsyncIteratorPrototypes::get(key);
167
+ if (proto_it.has_value()) return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key.to_std_string());
168
+ }
169
+ return Constants::UNDEFINED;
170
+ }
171
+ return AnyValue::resolve_property_for_read(it->second, thisVal, key.to_std_string());
172
+ }
173
+
174
+ template <typename T>
175
+ AnyValue JsAsyncIterator<T>::set_property(const std::string &key, AnyValue value, AnyValue thisVal)
176
+ {
177
+ if constexpr (std::is_same_v<T, AnyValue>) {
178
+ auto proto_it = AsyncIteratorPrototypes::get(key);
179
+ if (proto_it.has_value()) {
180
+ auto proto_value = proto_it.value();
181
+ if (proto_value.is_accessor_descriptor()) return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
182
+ if (proto_value.is_data_descriptor() && !proto_value.as_data_descriptor()->writable) return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
183
+ }
184
+ }
185
+ auto it = props.find(key);
186
+ if (it != props.end()) return jspp::AnyValue::resolve_property_for_write(it->second, thisVal, value, key);
187
+ else { props[key] = value; return value; }
188
+ }
189
+
190
+ template <typename T>
191
+ AnyValue JsAsyncIterator<T>::set_symbol_property(const AnyValue &key, AnyValue value, AnyValue thisVal)
192
+ {
193
+ auto it = symbol_props.find(key);
194
+ if (it != symbol_props.end()) return AnyValue::resolve_property_for_write(it->second, thisVal, value, key.to_std_string());
195
+ else { symbol_props[key] = value; return value; }
196
+ }
197
+
198
+ // Explicit template instantiation
199
+ template class JsAsyncIterator<AnyValue>;
200
+
201
+ namespace AsyncIteratorPrototypes {
202
+
203
+ AnyValue &get_toString_fn()
204
+ {
205
+ static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
206
+ { return AnyValue::make_string(thisVal.as_async_iterator()->to_std_string()); },
207
+ "toString");
208
+ return fn;
209
+ }
210
+
211
+ AnyValue &get_asyncIterator_fn()
212
+ {
213
+ static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
214
+ { return thisVal; },
215
+ "Symbol.asyncIterator");
216
+ return fn;
217
+ }
218
+
219
+ AnyValue &get_next_fn()
220
+ {
221
+ static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
222
+ {
223
+ AnyValue val = args.empty() ? Constants::UNDEFINED : args[0];
224
+ auto res = thisVal.as_async_iterator()->next(val);
225
+ return AnyValue::make_promise(res); },
226
+ "next");
227
+ return fn;
228
+ }
229
+
230
+ std::optional<AnyValue> get(const std::string &key)
231
+ {
232
+ if (key == "toString") return get_toString_fn();
233
+ if (key == "next") return get_next_fn();
234
+ return std::nullopt;
235
+ }
236
+
237
+ std::optional<AnyValue> get(const AnyValue &key)
238
+ {
239
+ if (key.is_string())
240
+ return get(key.as_string()->value);
241
+
242
+ if (key == AnyValue::from_symbol(WellKnownSymbols::toStringTag)) return get_toString_fn();
243
+ if (key == AnyValue::from_symbol(WellKnownSymbols::asyncIterator)) return get_asyncIterator_fn();
244
+ if (key == "next") return get_next_fn();
245
+
246
+ return std::nullopt;
247
+ }
248
+
249
+ } // namespace AsyncIteratorPrototypes
250
+
251
+ } // namespace jspp
@@ -4,16 +4,12 @@
4
4
  #include <coroutine>
5
5
  #include <optional>
6
6
  #include <queue>
7
- #include <iostream>
8
- #include <utility>
9
- #include <exception>
10
- #include "values/promise.hpp"
11
- #include "scheduler.hpp"
7
+ #include <vector>
12
8
 
13
9
  namespace jspp
14
10
  {
15
- // Forward declaration of AnyValue
16
11
  class AnyValue;
12
+ struct JsPromise;
17
13
 
18
14
  template <typename T>
19
15
  class JsAsyncIterator : public HeapObject
@@ -28,55 +24,87 @@ namespace jspp
28
24
  bool is_running = false;
29
25
  T current_input;
30
26
 
31
- JsAsyncIterator get_return_object()
32
- {
33
- return JsAsyncIterator{
34
- std::coroutine_handle<promise_type>::from_promise(*this)};
35
- }
27
+ JsAsyncIterator get_return_object();
28
+ std::suspend_always initial_suspend() noexcept;
29
+ std::suspend_always final_suspend() noexcept;
36
30
 
37
- std::suspend_always initial_suspend() noexcept { return {}; }
38
-
39
- std::suspend_always final_suspend() noexcept { return {}; }
31
+ struct YieldAwaiter
32
+ {
33
+ promise_type &p;
34
+ bool await_ready();
35
+ void await_suspend(std::coroutine_handle<promise_type> h);
36
+ T await_resume();
37
+ };
40
38
 
41
- // Declarations
42
39
  template <typename From>
43
- auto yield_value(From &&from);
40
+ YieldAwaiter yield_value(From &&from) {
41
+ if (!pending_calls.empty()) {
42
+ auto call = pending_calls.front();
43
+ pending_calls.pop();
44
+ AnyValue result = AnyValue::make_object({{"value", std::forward<From>(from)}, {"done", Constants::FALSE}});
45
+ call.first.resolve(result);
46
+ }
47
+ return YieldAwaiter{*this};
48
+ }
44
49
 
45
50
  template <typename From>
46
- void return_value(From &&from);
51
+ void return_value(From &&from) {
52
+ if (!pending_calls.empty()) {
53
+ auto call = pending_calls.front();
54
+ pending_calls.pop();
55
+ AnyValue result = AnyValue::make_object({{"value", std::forward<From>(from)}, {"done", Constants::TRUE}});
56
+ call.first.resolve(result);
57
+ }
58
+ while (!pending_calls.empty()) {
59
+ auto call = pending_calls.front();
60
+ pending_calls.pop();
61
+ AnyValue result = AnyValue::make_object({{"value", Constants::UNDEFINED}, {"done", Constants::TRUE}});
62
+ call.first.resolve(result);
63
+ }
64
+ }
47
65
 
48
66
  void unhandled_exception();
67
+
68
+ void fail_all(const AnyValue &reason) {
69
+ while (!pending_calls.empty()) {
70
+ auto call = pending_calls.front();
71
+ pending_calls.pop();
72
+ call.first.reject(reason);
73
+ }
74
+ }
49
75
 
50
- void fail_all(const AnyValue &reason);
76
+ struct AsyncIterAwaiter
77
+ {
78
+ AnyValueAwaiter base_awaiter;
79
+ promise_type &p_ref;
80
+
81
+ bool await_ready();
82
+ void await_suspend(std::coroutine_handle<promise_type> h);
83
+ AnyValue await_resume();
84
+ };
51
85
 
52
- auto await_transform(AnyValue value);
86
+ AsyncIterAwaiter await_transform(AnyValue value);
53
87
  };
54
88
 
55
89
  using handle_type = std::coroutine_handle<promise_type>;
56
90
  handle_type handle;
57
91
 
58
- explicit JsAsyncIterator(handle_type h) : handle(h) {}
59
- JsAsyncIterator(JsAsyncIterator &&other) noexcept
60
- : handle(std::exchange(other.handle, nullptr)),
61
- props(std::move(other.props)) {}
62
-
92
+ explicit JsAsyncIterator(handle_type h);
93
+ JsAsyncIterator(JsAsyncIterator &&other) noexcept;
63
94
  JsAsyncIterator(const JsAsyncIterator &) = delete;
64
95
  JsAsyncIterator &operator=(const JsAsyncIterator &) = delete;
65
-
66
- ~JsAsyncIterator()
67
- {
68
- if (handle)
69
- handle.destroy();
70
- }
96
+ ~JsAsyncIterator();
71
97
 
72
98
  std::unordered_map<std::string, AnyValue> props;
99
+ std::map<AnyValue, AnyValue> symbol_props;
73
100
 
74
101
  std::string to_std_string() const;
75
-
76
102
  JsPromise next(const T &val = T());
77
-
103
+ bool has_symbol_property(const AnyValue &key) const;
78
104
  AnyValue get_property(const std::string &key, AnyValue thisVal);
105
+ AnyValue get_symbol_property(const AnyValue &key, AnyValue thisVal);
79
106
  AnyValue set_property(const std::string &key, AnyValue value, AnyValue thisVal);
107
+ AnyValue set_symbol_property(const AnyValue &key, AnyValue value, AnyValue thisVal);
80
108
 
81
109
  void resume_next();
82
110
  };
@@ -0,0 +1,64 @@
1
+ #include "jspp.hpp"
2
+ #include "values/prototypes/boolean.hpp"
3
+
4
+ namespace jspp
5
+ {
6
+
7
+ // --- JsBoolean Implementation ---
8
+
9
+ namespace JsBoolean
10
+ {
11
+ std::string to_std_string(bool value)
12
+ {
13
+ return value ? "true" : "false";
14
+ }
15
+
16
+ std::string to_std_string(const AnyValue &value)
17
+ {
18
+ return to_std_string(value.as_boolean());
19
+ }
20
+
21
+ }
22
+
23
+ // --- BooleanPrototypes Implementation ---
24
+
25
+ namespace BooleanPrototypes
26
+ {
27
+
28
+ AnyValue &get_toString_fn()
29
+ {
30
+ static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
31
+ { return AnyValue::make_string(JsBoolean::to_std_string(thisVal.as_boolean())); },
32
+ "toString");
33
+ return fn;
34
+ }
35
+
36
+ AnyValue &get_valueOf_fn()
37
+ {
38
+ static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue>) -> AnyValue
39
+ { return AnyValue::make_boolean(thisVal.as_boolean()); },
40
+ "valueOf");
41
+ return fn;
42
+ }
43
+
44
+ std::optional<AnyValue> get(const std::string &key)
45
+ {
46
+ if (key == "toString")
47
+ return get_toString_fn();
48
+ if (key == "valueOf")
49
+ return get_valueOf_fn();
50
+ return std::nullopt;
51
+ }
52
+
53
+ std::optional<AnyValue> get(const AnyValue &key)
54
+ {
55
+ if (key == "toString")
56
+ return get_toString_fn();
57
+ if (key == "valueOf")
58
+ return get_valueOf_fn();
59
+ return std::nullopt;
60
+ }
61
+
62
+ } // namespace BooleanPrototypes
63
+
64
+ } // namespace jspp