@ugo-studio/jspp 0.1.8 → 0.2.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/README.md +1 -1
- package/dist/cli-utils/args.js +2 -0
- package/dist/cli.js +1 -1
- package/package.json +3 -2
- package/scripts/precompile-headers.ts +110 -0
- package/scripts/setup-compiler.ts +63 -0
- package/src/prelude/any_value.hpp +185 -391
- package/src/prelude/any_value_access.hpp +170 -190
- package/src/prelude/any_value_defines.hpp +12 -12
- package/src/prelude/any_value_helpers.hpp +208 -26
- package/src/prelude/exception.hpp +27 -31
- package/src/prelude/exception_helpers.hpp +53 -49
- package/src/prelude/index.hpp +9 -4
- package/src/prelude/library/array.hpp +4 -9
- package/src/prelude/library/console.hpp +112 -112
- package/src/prelude/library/error.hpp +8 -8
- package/src/prelude/library/math.hpp +3 -3
- package/src/prelude/library/object.hpp +12 -24
- package/src/prelude/library/promise.hpp +1 -1
- package/src/prelude/library/symbol.hpp +1 -1
- package/src/prelude/library/timer.hpp +3 -3
- package/src/prelude/types.hpp +178 -130
- package/src/prelude/utils/access.hpp +338 -378
- package/src/prelude/utils/log_any_value/function.hpp +39 -39
- package/src/prelude/utils/log_any_value/log_any_value.hpp +1 -1
- package/src/prelude/utils/operators.hpp +20 -82
- package/src/prelude/utils/well_known_symbols.hpp +14 -15
- package/src/prelude/values/array.hpp +5 -3
- package/src/prelude/values/async_iterator.hpp +3 -1
- package/src/prelude/values/descriptors.hpp +15 -3
- package/src/prelude/values/function.hpp +5 -9
- package/src/prelude/values/helpers/array.hpp +208 -219
- package/src/prelude/values/helpers/async_iterator.hpp +7 -11
- package/src/prelude/values/helpers/function.hpp +12 -17
- package/src/prelude/values/helpers/iterator.hpp +108 -107
- package/src/prelude/values/helpers/object.hpp +104 -109
- package/src/prelude/values/helpers/promise.hpp +185 -119
- package/src/prelude/values/helpers/string.hpp +7 -10
- package/src/prelude/values/helpers/symbol.hpp +21 -23
- package/src/prelude/values/iterator.hpp +4 -1
- package/src/prelude/values/object.hpp +6 -4
- package/src/prelude/values/promise.hpp +5 -2
- package/src/prelude/values/prototypes/array.hpp +22 -22
- package/src/prelude/values/prototypes/async_iterator.hpp +3 -10
- package/src/prelude/values/prototypes/iterator.hpp +51 -58
- package/src/prelude/values/prototypes/promise.hpp +32 -28
- package/src/prelude/values/prototypes/string.hpp +5 -5
- package/src/prelude/values/prototypes/symbol.hpp +1 -1
- package/src/prelude/values/string.hpp +3 -1
- package/src/prelude/values/symbol.hpp +101 -102
|
@@ -1,107 +1,108 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "values/iterator.hpp"
|
|
5
|
-
#include "any_value.hpp"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// If handle.done() is
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if
|
|
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
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "values/iterator.hpp"
|
|
5
|
+
#include "any_value.hpp"
|
|
6
|
+
#include "values/prototypes/iterator.hpp"
|
|
7
|
+
|
|
8
|
+
template <typename T>
|
|
9
|
+
std::string jspp::JsIterator<T>::to_std_string() const
|
|
10
|
+
{
|
|
11
|
+
return "[object Generator]";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
template <typename T>
|
|
15
|
+
typename jspp::JsIterator<T>::NextResult jspp::JsIterator<T>::next(const T &val)
|
|
16
|
+
{
|
|
17
|
+
// If the generator is already finished or invalid, return {undefined, true}
|
|
18
|
+
if (!handle || handle.done())
|
|
19
|
+
return {std::nullopt, true};
|
|
20
|
+
|
|
21
|
+
handle.promise().input_value = val;
|
|
22
|
+
|
|
23
|
+
// Resume execution until next co_yield or co_return
|
|
24
|
+
handle.resume();
|
|
25
|
+
|
|
26
|
+
if (handle.promise().exception_)
|
|
27
|
+
{
|
|
28
|
+
std::rethrow_exception(handle.promise().exception_);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If handle.done() is TRUE, we hit co_return (value: X, done: true)
|
|
32
|
+
// If handle.done() is FALSE, we hit co_yield (value: X, done: false)
|
|
33
|
+
bool is_done = handle.done();
|
|
34
|
+
|
|
35
|
+
return {handle.promise().current_value, is_done};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
template <typename T>
|
|
39
|
+
std::vector<T> jspp::JsIterator<T>::to_vector()
|
|
40
|
+
{
|
|
41
|
+
std::vector<T> result;
|
|
42
|
+
while (true)
|
|
43
|
+
{
|
|
44
|
+
auto next_res = this->next();
|
|
45
|
+
if (next_res.done)
|
|
46
|
+
{
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
result.push_back(next_res.value.value_or(Constants::UNDEFINED));
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
template <typename T>
|
|
55
|
+
jspp::AnyValue jspp::JsIterator<T>::get_property(const std::string &key, const AnyValue &thisVal)
|
|
56
|
+
{
|
|
57
|
+
auto it = props.find(key);
|
|
58
|
+
if (it == props.end())
|
|
59
|
+
{
|
|
60
|
+
// check prototype
|
|
61
|
+
if constexpr (std::is_same_v<T, AnyValue>)
|
|
62
|
+
{
|
|
63
|
+
auto proto_it = IteratorPrototypes::get(key, this);
|
|
64
|
+
if (proto_it.has_value())
|
|
65
|
+
{
|
|
66
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// prototype not found
|
|
70
|
+
return Constants::UNDEFINED;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return AnyValue::resolve_property_for_read(it->second, thisVal, key);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
template <typename T>
|
|
77
|
+
jspp::AnyValue jspp::JsIterator<T>::set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal)
|
|
78
|
+
{
|
|
79
|
+
// set prototype property if accessor descriptor
|
|
80
|
+
if constexpr (std::is_same_v<T, AnyValue>)
|
|
81
|
+
{
|
|
82
|
+
auto proto_it = IteratorPrototypes::get(key, this);
|
|
83
|
+
if (proto_it.has_value())
|
|
84
|
+
{
|
|
85
|
+
auto proto_value = proto_it.value();
|
|
86
|
+
if (proto_value.is_accessor_descriptor())
|
|
87
|
+
{
|
|
88
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
89
|
+
}
|
|
90
|
+
if (proto_value.is_data_descriptor() && !proto_value.as_data_descriptor()->writable)
|
|
91
|
+
{
|
|
92
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// set own property
|
|
98
|
+
auto it = props.find(key);
|
|
99
|
+
if (it != props.end())
|
|
100
|
+
{
|
|
101
|
+
return jspp::AnyValue::resolve_property_for_write(it->second, thisVal, value, key);
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
{
|
|
105
|
+
props[key] = value;
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1,109 +1,104 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "values/object.hpp"
|
|
5
|
-
#include "any_value.hpp"
|
|
6
|
-
|
|
7
|
-
namespace jspp {
|
|
8
|
-
JsObject::JsObject() : shape(Shape::empty_shape()), proto(
|
|
9
|
-
|
|
10
|
-
JsObject::JsObject(std::initializer_list<std::pair<std::string, AnyValue>> p,
|
|
11
|
-
shape = Shape::empty_shape();
|
|
12
|
-
storage.reserve(p.size());
|
|
13
|
-
for (const auto& pair : p) {
|
|
14
|
-
shape = shape->transition(pair.first);
|
|
15
|
-
storage.push_back(pair.second);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
JsObject::JsObject(const std::map<std::string, AnyValue> &p,
|
|
20
|
-
shape = Shape::empty_shape();
|
|
21
|
-
storage.reserve(p.size());
|
|
22
|
-
for (const auto& pair : p) {
|
|
23
|
-
shape = shape->transition(pair.first);
|
|
24
|
-
storage.push_back(pair.second);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
std::string jspp::JsObject::to_std_string() const
|
|
30
|
-
{
|
|
31
|
-
return "[Object Object]";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
bool jspp::JsObject::has_property(const std::string &key) const
|
|
35
|
-
{
|
|
36
|
-
if (deleted_keys.count(key)) return false;
|
|
37
|
-
|
|
38
|
-
if (shape->get_offset(key).has_value())
|
|
39
|
-
return true;
|
|
40
|
-
if (
|
|
41
|
-
{
|
|
42
|
-
if (
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
if (ObjectPrototypes::get(key, const_cast<JsObject *>(this)).has_value())
|
|
46
|
-
return true;
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
jspp::AnyValue jspp::JsObject::get_property(const std::string &key, const AnyValue &thisVal)
|
|
51
|
-
{
|
|
52
|
-
if (deleted_keys.count(key)) return
|
|
53
|
-
|
|
54
|
-
auto offset = shape->get_offset(key);
|
|
55
|
-
if (!offset.has_value())
|
|
56
|
-
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (proto_value.
|
|
86
|
-
{
|
|
87
|
-
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
shape = shape->transition(key);
|
|
106
|
-
storage.push_back(value);
|
|
107
|
-
return value;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "values/object.hpp"
|
|
5
|
+
#include "any_value.hpp"
|
|
6
|
+
|
|
7
|
+
namespace jspp {
|
|
8
|
+
inline JsObject::JsObject() : shape(Shape::empty_shape()), proto(Constants::Null) {}
|
|
9
|
+
|
|
10
|
+
inline JsObject::JsObject(std::initializer_list<std::pair<std::string, AnyValue>> p, AnyValue pr) : proto(pr) {
|
|
11
|
+
shape = Shape::empty_shape();
|
|
12
|
+
storage.reserve(p.size());
|
|
13
|
+
for (const auto& pair : p) {
|
|
14
|
+
shape = shape->transition(pair.first);
|
|
15
|
+
storage.push_back(pair.second);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
inline JsObject::JsObject(const std::map<std::string, AnyValue> &p, AnyValue pr) : proto(pr) {
|
|
20
|
+
shape = Shape::empty_shape();
|
|
21
|
+
storage.reserve(p.size());
|
|
22
|
+
for (const auto& pair : p) {
|
|
23
|
+
shape = shape->transition(pair.first);
|
|
24
|
+
storage.push_back(pair.second);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
inline std::string jspp::JsObject::to_std_string() const
|
|
30
|
+
{
|
|
31
|
+
return "[Object Object]";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
inline bool jspp::JsObject::has_property(const std::string &key) const
|
|
35
|
+
{
|
|
36
|
+
if (deleted_keys.count(key)) return false;
|
|
37
|
+
|
|
38
|
+
if (shape->get_offset(key).has_value())
|
|
39
|
+
return true;
|
|
40
|
+
if (!proto.is_null() && !proto.is_undefined())
|
|
41
|
+
{
|
|
42
|
+
if (proto.has_property(key))
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (ObjectPrototypes::get(key, const_cast<JsObject *>(this)).has_value())
|
|
46
|
+
return true;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
inline jspp::AnyValue jspp::JsObject::get_property(const std::string &key, const AnyValue &thisVal)
|
|
51
|
+
{
|
|
52
|
+
if (deleted_keys.count(key)) return Constants::UNDEFINED;
|
|
53
|
+
|
|
54
|
+
auto offset = shape->get_offset(key);
|
|
55
|
+
if (!offset.has_value())
|
|
56
|
+
{
|
|
57
|
+
if (!proto.is_null() && !proto.is_undefined())
|
|
58
|
+
{
|
|
59
|
+
if (proto.has_property(key))
|
|
60
|
+
{
|
|
61
|
+
return proto.get_property_with_receiver(key, thisVal);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
auto proto_it = ObjectPrototypes::get(key, this);
|
|
66
|
+
if (proto_it.has_value())
|
|
67
|
+
{
|
|
68
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key);
|
|
69
|
+
}
|
|
70
|
+
return Constants::UNDEFINED;
|
|
71
|
+
}
|
|
72
|
+
return AnyValue::resolve_property_for_read(storage[offset.value()], thisVal, key);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
inline jspp::AnyValue jspp::JsObject::set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal)
|
|
76
|
+
{
|
|
77
|
+
auto proto_it = ObjectPrototypes::get(key, this);
|
|
78
|
+
if (proto_it.has_value())
|
|
79
|
+
{
|
|
80
|
+
auto proto_value = proto_it.value();
|
|
81
|
+
if (proto_value.is_accessor_descriptor())
|
|
82
|
+
{
|
|
83
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
84
|
+
}
|
|
85
|
+
if (proto_value.is_data_descriptor() && !proto_value.as_data_descriptor()->writable)
|
|
86
|
+
{
|
|
87
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (deleted_keys.count(key)) deleted_keys.erase(key);
|
|
92
|
+
|
|
93
|
+
auto offset = shape->get_offset(key);
|
|
94
|
+
if (offset.has_value())
|
|
95
|
+
{
|
|
96
|
+
return AnyValue::resolve_property_for_write(storage[offset.value()], thisVal, value, key);
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
shape = shape->transition(key);
|
|
101
|
+
storage.push_back(value);
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
}
|