@ugo-studio/jspp 0.1.3 → 0.1.4
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 +2 -2
- package/dist/analysis/scope.js +16 -4
- package/dist/analysis/typeAnalyzer.js +253 -20
- package/dist/ast/types.js +6 -0
- package/dist/cli.js +1 -2
- package/dist/core/codegen/class-handlers.js +127 -0
- package/dist/core/codegen/control-flow-handlers.js +464 -0
- package/dist/core/codegen/declaration-handlers.js +31 -14
- package/dist/core/codegen/expression-handlers.js +429 -117
- package/dist/core/codegen/function-handlers.js +91 -15
- package/dist/core/codegen/helpers.js +66 -2
- package/dist/core/codegen/index.js +17 -6
- package/dist/core/codegen/literal-handlers.js +3 -0
- package/dist/core/codegen/statement-handlers.js +133 -204
- package/dist/core/codegen/visitor.js +29 -3
- package/package.json +3 -3
- package/src/prelude/any_value.hpp +658 -634
- package/src/prelude/any_value_access.hpp +103 -0
- package/src/prelude/any_value_defines.hpp +151 -0
- package/src/prelude/any_value_helpers.hpp +246 -225
- package/src/prelude/exception.hpp +31 -0
- package/src/prelude/exception_helpers.hpp +49 -0
- package/src/prelude/index.hpp +18 -9
- package/src/prelude/library/console.hpp +13 -13
- package/src/prelude/library/error.hpp +111 -0
- package/src/prelude/library/global.hpp +15 -4
- package/src/prelude/library/performance.hpp +2 -2
- package/src/prelude/library/promise.hpp +121 -0
- package/src/prelude/library/symbol.hpp +3 -4
- package/src/prelude/library/timer.hpp +92 -0
- package/src/prelude/scheduler.hpp +145 -0
- package/src/prelude/types.hpp +10 -1
- package/src/prelude/utils/access.hpp +174 -0
- package/src/prelude/utils/log_any_value/array.hpp +245 -0
- package/src/prelude/utils/log_any_value/config.hpp +32 -0
- package/src/prelude/utils/log_any_value/function.hpp +37 -0
- package/src/prelude/utils/log_any_value/fwd.hpp +15 -0
- package/src/prelude/utils/log_any_value/helpers.hpp +62 -0
- package/src/prelude/utils/log_any_value/log_any_value.hpp +94 -0
- package/src/prelude/utils/log_any_value/object.hpp +119 -0
- package/src/prelude/utils/log_any_value/primitives.hpp +41 -0
- package/src/prelude/{operators.hpp → utils/operators.hpp} +29 -10
- package/src/prelude/{well_known_symbols.hpp → utils/well_known_symbols.hpp} +0 -1
- package/src/prelude/values/array.hpp +3 -2
- package/src/prelude/{descriptors.hpp → values/descriptors.hpp} +2 -2
- package/src/prelude/values/function.hpp +76 -51
- package/src/prelude/values/helpers/array.hpp +20 -11
- package/src/prelude/values/helpers/function.hpp +125 -77
- package/src/prelude/values/helpers/iterator.hpp +13 -7
- package/src/prelude/values/helpers/object.hpp +36 -6
- package/src/prelude/values/helpers/promise.hpp +181 -0
- package/src/prelude/values/helpers/string.hpp +3 -3
- package/src/prelude/values/helpers/symbol.hpp +2 -2
- package/src/prelude/values/iterator.hpp +13 -5
- package/src/prelude/values/object.hpp +6 -2
- package/src/prelude/values/promise.hpp +73 -0
- package/src/prelude/values/prototypes/array.hpp +16 -16
- package/src/prelude/values/prototypes/function.hpp +4 -4
- package/src/prelude/values/prototypes/iterator.hpp +11 -10
- package/src/prelude/values/prototypes/object.hpp +26 -0
- package/src/prelude/values/prototypes/promise.hpp +124 -0
- package/src/prelude/values/prototypes/string.hpp +26 -26
- package/src/prelude/values/prototypes/symbol.hpp +5 -3
- package/src/prelude/values/string.hpp +1 -1
- package/src/prelude/values/symbol.hpp +1 -1
- package/src/prelude/access.hpp +0 -91
- package/src/prelude/error.hpp +0 -31
- package/src/prelude/error_helpers.hpp +0 -59
- package/src/prelude/log_string.hpp +0 -407
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "types.hpp"
|
|
3
|
+
#include "any_value.hpp"
|
|
4
|
+
#include "library/error.hpp"
|
|
5
|
+
#include "utils/log_any_value/config.hpp"
|
|
6
|
+
#include "utils/log_any_value/helpers.hpp"
|
|
7
|
+
#include "utils/log_any_value/fwd.hpp" // Required for recursive to_log_string call
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <sstream>
|
|
10
|
+
#include <unordered_set>
|
|
11
|
+
|
|
12
|
+
namespace jspp
|
|
13
|
+
{
|
|
14
|
+
namespace LogAnyValue
|
|
15
|
+
{
|
|
16
|
+
inline std::string format_object(const AnyValue &val, std::unordered_set<const void *> &visited, int depth)
|
|
17
|
+
{
|
|
18
|
+
auto obj = val.as_object();
|
|
19
|
+
|
|
20
|
+
size_t prop_count = obj->props.size();
|
|
21
|
+
bool use_horizontal_layout = prop_count > 0 && prop_count <= HORIZONTAL_OBJECT_MAX_PROPS;
|
|
22
|
+
|
|
23
|
+
if (use_horizontal_layout)
|
|
24
|
+
{
|
|
25
|
+
for (const auto &pair : obj->props)
|
|
26
|
+
{
|
|
27
|
+
if (!is_simple_value(pair.second))
|
|
28
|
+
{
|
|
29
|
+
use_horizontal_layout = false;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
std::string indent(depth * 2, ' ');
|
|
36
|
+
std::string next_indent((depth + 1) * 2, ' ');
|
|
37
|
+
std::stringstream ss;
|
|
38
|
+
|
|
39
|
+
// Special handling for Error objects
|
|
40
|
+
try
|
|
41
|
+
{
|
|
42
|
+
auto is_error = isErrorFn.as_function()->call(isErrorFn, {val}).is_truthy();
|
|
43
|
+
if (is_error)
|
|
44
|
+
{
|
|
45
|
+
auto result = errorToStringFn.as_function()->call(val, {});
|
|
46
|
+
if (result.is_string())
|
|
47
|
+
{
|
|
48
|
+
ss << result.to_std_string() << " ";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (...)
|
|
53
|
+
{
|
|
54
|
+
// ignore
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (use_horizontal_layout)
|
|
58
|
+
{
|
|
59
|
+
ss << "{ ";
|
|
60
|
+
size_t current_prop = 0;
|
|
61
|
+
for (const auto &pair : obj->props)
|
|
62
|
+
{
|
|
63
|
+
if (!is_enumerable_property(pair.second))
|
|
64
|
+
continue;
|
|
65
|
+
|
|
66
|
+
if (is_valid_js_identifier(pair.first))
|
|
67
|
+
{
|
|
68
|
+
ss << pair.first;
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
{
|
|
72
|
+
ss << "\"" << pair.first << "\"";
|
|
73
|
+
}
|
|
74
|
+
ss << ": " << to_log_string(pair.second, visited, depth + 1);
|
|
75
|
+
if (++current_prop < prop_count)
|
|
76
|
+
ss << Color::BRIGHT_BLACK << ", " << Color::RESET;
|
|
77
|
+
}
|
|
78
|
+
ss << " }";
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
ss << "{";
|
|
83
|
+
if (prop_count > 0)
|
|
84
|
+
{
|
|
85
|
+
ss << "\n";
|
|
86
|
+
size_t props_shown = 0;
|
|
87
|
+
for (const auto &pair : obj->props)
|
|
88
|
+
{
|
|
89
|
+
if (props_shown >= MAX_OBJECT_PROPS)
|
|
90
|
+
break;
|
|
91
|
+
if (props_shown > 0)
|
|
92
|
+
ss << ",\n";
|
|
93
|
+
if (!is_enumerable_property(pair.second))
|
|
94
|
+
continue;
|
|
95
|
+
|
|
96
|
+
ss << next_indent;
|
|
97
|
+
if (is_valid_js_identifier(pair.first))
|
|
98
|
+
{
|
|
99
|
+
ss << pair.first;
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
{
|
|
103
|
+
ss << "\"" << pair.first << "\"";
|
|
104
|
+
}
|
|
105
|
+
ss << ": " << to_log_string(pair.second, visited, depth + 1);
|
|
106
|
+
props_shown++;
|
|
107
|
+
}
|
|
108
|
+
if (prop_count > MAX_OBJECT_PROPS)
|
|
109
|
+
ss << ",\n"
|
|
110
|
+
<< next_indent << Color::BRIGHT_BLACK << "... " << (prop_count - MAX_OBJECT_PROPS) << " more properties" << Color::RESET;
|
|
111
|
+
ss << "\n"
|
|
112
|
+
<< indent;
|
|
113
|
+
}
|
|
114
|
+
ss << "}";
|
|
115
|
+
}
|
|
116
|
+
return ss.str();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "types.hpp"
|
|
3
|
+
#include "any_value.hpp"
|
|
4
|
+
#include "utils/log_any_value/config.hpp"
|
|
5
|
+
#include "utils/log_any_value/helpers.hpp"
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <optional>
|
|
8
|
+
|
|
9
|
+
namespace jspp
|
|
10
|
+
{
|
|
11
|
+
namespace LogAnyValue
|
|
12
|
+
{
|
|
13
|
+
inline std::optional<std::string> format_primitive(const AnyValue &val, int depth)
|
|
14
|
+
{
|
|
15
|
+
if (val.is_uninitialized())
|
|
16
|
+
return Color::BRIGHT_BLACK + std::string("<uninitialized>") + Color::RESET;
|
|
17
|
+
if (val.is_undefined())
|
|
18
|
+
return Color::BRIGHT_BLACK + std::string("undefined") + Color::RESET;
|
|
19
|
+
if (val.is_null())
|
|
20
|
+
return Color::MAGENTA + std::string("null") + Color::RESET;
|
|
21
|
+
if (val.is_boolean())
|
|
22
|
+
return Color::YELLOW + std::string(val.as_boolean() ? "true" : "false") + Color::RESET;
|
|
23
|
+
if (val.is_number())
|
|
24
|
+
return Color::YELLOW + val.to_std_string() + Color::RESET;
|
|
25
|
+
if (val.is_symbol())
|
|
26
|
+
return Color::BLUE + val.to_std_string() + Color::RESET;
|
|
27
|
+
if (val.is_accessor_descriptor())
|
|
28
|
+
return Color::BLUE + std::string("[Getter/Setter]") + Color::RESET;
|
|
29
|
+
|
|
30
|
+
if (val.is_string())
|
|
31
|
+
{
|
|
32
|
+
const std::string &s = val.as_string()->value;
|
|
33
|
+
if (depth == 0)
|
|
34
|
+
return truncate_string(s);
|
|
35
|
+
return Color::GREEN + std::string("\"") + truncate_string(s) + "\"" + Color::RESET;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return std::nullopt; // Not a primitive
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -13,15 +13,18 @@ namespace jspp
|
|
|
13
13
|
// Implements the ToNumber abstract operation from ECMA-262.
|
|
14
14
|
inline double ToNumber(const AnyValue &val)
|
|
15
15
|
{
|
|
16
|
-
|
|
16
|
+
switch (val.get_type())
|
|
17
|
+
{
|
|
18
|
+
case JsType::Number:
|
|
17
19
|
return val.as_double();
|
|
18
|
-
|
|
20
|
+
case JsType::Null:
|
|
19
21
|
return 0.0;
|
|
20
|
-
|
|
22
|
+
case JsType::Uninitialized:
|
|
23
|
+
case JsType::Undefined:
|
|
21
24
|
return std::numeric_limits<double>::quiet_NaN();
|
|
22
|
-
|
|
25
|
+
case JsType::Boolean:
|
|
23
26
|
return val.as_boolean() ? 1.0 : 0.0;
|
|
24
|
-
|
|
27
|
+
case JsType::String:
|
|
25
28
|
{
|
|
26
29
|
const std::string &s = val.as_string()->value;
|
|
27
30
|
// JS considers empty or whitespace-only strings as 0.
|
|
@@ -43,9 +46,11 @@ namespace jspp
|
|
|
43
46
|
return std::numeric_limits<double>::quiet_NaN();
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
default:
|
|
50
|
+
// In a full engine, objects would be converted via valueOf/toString.
|
|
51
|
+
// Here we simplify and return NaN.
|
|
52
|
+
return std::numeric_limits<double>::quiet_NaN();
|
|
53
|
+
}
|
|
49
54
|
}
|
|
50
55
|
// Implements the ToInt32 abstract operation from ECMA-262.
|
|
51
56
|
inline int32_t ToInt32(const AnyValue &val)
|
|
@@ -144,11 +149,25 @@ namespace jspp
|
|
|
144
149
|
}
|
|
145
150
|
inline AnyValue operator==(const AnyValue &lhs, const AnyValue &rhs)
|
|
146
151
|
{
|
|
147
|
-
return AnyValue::make_boolean(lhs.
|
|
152
|
+
return AnyValue::make_boolean(lhs.is_equal_to_primitive(rhs));
|
|
148
153
|
}
|
|
149
154
|
inline AnyValue operator!=(const AnyValue &lhs, const AnyValue &rhs)
|
|
150
155
|
{
|
|
151
|
-
return AnyValue::make_boolean(!lhs.
|
|
156
|
+
return AnyValue::make_boolean(!lhs.is_equal_to_primitive(rhs));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// --- LOGICAL OPERATORS
|
|
160
|
+
inline AnyValue operator||(const AnyValue &lhs, const AnyValue &rhs)
|
|
161
|
+
{
|
|
162
|
+
if (lhs.is_truthy())
|
|
163
|
+
return lhs;
|
|
164
|
+
return rhs;
|
|
165
|
+
}
|
|
166
|
+
inline AnyValue operator&&(const AnyValue &lhs, const AnyValue &rhs)
|
|
167
|
+
{
|
|
168
|
+
if (!lhs.is_truthy())
|
|
169
|
+
return lhs;
|
|
170
|
+
return rhs;
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
// --- BITWISE OPERATORS
|
|
@@ -9,6 +9,5 @@ namespace jspp
|
|
|
9
9
|
{
|
|
10
10
|
// We use a specific prefix "@@" for well-known symbols to distinguish them from user symbols
|
|
11
11
|
inline std::shared_ptr<JsSymbol> iterator = std::make_shared<JsSymbol>("Symbol.iterator", "@@iterator");
|
|
12
|
-
inline std::shared_ptr<JsSymbol> toString = std::make_shared<JsSymbol>("Symbol.toString", "@@toString");
|
|
13
12
|
}
|
|
14
13
|
}
|
|
@@ -17,13 +17,14 @@ namespace jspp
|
|
|
17
17
|
|
|
18
18
|
JsArray() = default;
|
|
19
19
|
explicit JsArray(const std::vector<std::optional<AnyValue>> &items) : dense(items), length(items.size()) {}
|
|
20
|
+
explicit JsArray(std::vector<std::optional<AnyValue>> &&items) : dense(std::move(items)), length(dense.size()) {}
|
|
20
21
|
|
|
21
22
|
std::string to_std_string() const;
|
|
22
23
|
JsIterator<AnyValue> get_iterator();
|
|
23
24
|
|
|
24
|
-
AnyValue get_property(const std::string &key);
|
|
25
|
+
AnyValue get_property(const std::string &key, const AnyValue &thisVal);
|
|
25
26
|
AnyValue get_property(uint32_t idx);
|
|
26
|
-
AnyValue set_property(const std::string &key, const AnyValue &value);
|
|
27
|
+
AnyValue set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal);
|
|
27
28
|
AnyValue set_property(uint32_t idx, const AnyValue &value);
|
|
28
29
|
|
|
29
30
|
static bool is_array_index(const std::string &s)
|
|
@@ -17,8 +17,8 @@ namespace jspp
|
|
|
17
17
|
|
|
18
18
|
struct AccessorDescriptor
|
|
19
19
|
{
|
|
20
|
-
std::optional<std::function<AnyValue(const std::vector<AnyValue> &)>> get; // getter = function or undefined
|
|
21
|
-
std::optional<std::function<AnyValue(const std::vector<AnyValue> &)>> set; // setter = function or undefined
|
|
20
|
+
std::optional<std::function<AnyValue(const AnyValue &, const std::vector<AnyValue> &)>> get; // getter = function or undefined
|
|
21
|
+
std::optional<std::function<AnyValue(const AnyValue &, const std::vector<AnyValue> &)>> set; // setter = function or undefined
|
|
22
22
|
bool enumerable = false;
|
|
23
23
|
bool configurable = true;
|
|
24
24
|
};
|
|
@@ -1,51 +1,76 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include <variant> // Ensure variant is included
|
|
5
|
+
|
|
6
|
+
namespace jspp
|
|
7
|
+
{
|
|
8
|
+
// Forward declaration of AnyValue
|
|
9
|
+
class AnyValue;
|
|
10
|
+
|
|
11
|
+
using JsFunctionCallable = std::variant<std::function<AnyValue(const AnyValue &, const std::vector<AnyValue> &)>, // 0: Normal
|
|
12
|
+
std::function<jspp::JsIterator<jspp::AnyValue>(const AnyValue &, const std::vector<jspp::AnyValue> &)>, // 1: Generator
|
|
13
|
+
std::function<jspp::JsPromise(const AnyValue &, const std::vector<jspp::AnyValue> &)>>; // 2: Async
|
|
14
|
+
|
|
15
|
+
struct JsFunction
|
|
16
|
+
{
|
|
17
|
+
JsFunctionCallable callable;
|
|
18
|
+
std::string name;
|
|
19
|
+
std::unordered_map<std::string, AnyValue> props;
|
|
20
|
+
std::shared_ptr<AnyValue> proto = nullptr;
|
|
21
|
+
bool is_generator;
|
|
22
|
+
bool is_async;
|
|
23
|
+
bool is_class;
|
|
24
|
+
|
|
25
|
+
// ---- Constructor A: infer flags ----
|
|
26
|
+
JsFunction(const JsFunctionCallable &c,
|
|
27
|
+
std::string n = {},
|
|
28
|
+
std::unordered_map<std::string, AnyValue> p = {},
|
|
29
|
+
bool is_cls = false)
|
|
30
|
+
: callable(c),
|
|
31
|
+
name(std::move(n)),
|
|
32
|
+
props(std::move(p)),
|
|
33
|
+
is_generator(callable.index() == 1),
|
|
34
|
+
is_async(callable.index() == 2),
|
|
35
|
+
is_class(is_cls)
|
|
36
|
+
{
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ---- Constructor B: explicit generator flag (backward compat) ----
|
|
40
|
+
JsFunction(const JsFunctionCallable &c,
|
|
41
|
+
bool is_gen,
|
|
42
|
+
std::string n = {},
|
|
43
|
+
std::unordered_map<std::string, AnyValue> p = {},
|
|
44
|
+
bool is_cls = false)
|
|
45
|
+
: callable(c),
|
|
46
|
+
name(std::move(n)),
|
|
47
|
+
props(std::move(p)),
|
|
48
|
+
is_generator(is_gen),
|
|
49
|
+
is_async(callable.index() == 2),
|
|
50
|
+
is_class(is_cls)
|
|
51
|
+
{
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ---- Constructor C: explicit async flag ----
|
|
55
|
+
JsFunction(const JsFunctionCallable &c,
|
|
56
|
+
bool is_gen,
|
|
57
|
+
bool is_async_func,
|
|
58
|
+
std::string n = {},
|
|
59
|
+
std::unordered_map<std::string, AnyValue> p = {},
|
|
60
|
+
bool is_cls = false)
|
|
61
|
+
: callable(c),
|
|
62
|
+
name(std::move(n)),
|
|
63
|
+
props(std::move(p)),
|
|
64
|
+
is_generator(is_gen),
|
|
65
|
+
is_async(is_async_func),
|
|
66
|
+
is_class(is_cls)
|
|
67
|
+
{
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
std::string to_std_string() const;
|
|
71
|
+
AnyValue call(const AnyValue &thisVal, const std::vector<AnyValue> &args);
|
|
72
|
+
|
|
73
|
+
AnyValue get_property(const std::string &key, const AnyValue &thisVal);
|
|
74
|
+
AnyValue set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include "types.hpp"
|
|
4
4
|
#include "values/array.hpp"
|
|
5
|
-
#include "
|
|
5
|
+
#include "exception.hpp"
|
|
6
6
|
#include "any_value.hpp"
|
|
7
7
|
#include "values/prototypes/array.hpp"
|
|
8
8
|
|
|
@@ -57,7 +57,7 @@ jspp::JsIterator<jspp::AnyValue> jspp::JsArray::get_iterator()
|
|
|
57
57
|
co_return AnyValue::make_undefined();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
jspp::AnyValue jspp::JsArray::get_property(const std::string &key)
|
|
60
|
+
jspp::AnyValue jspp::JsArray::get_property(const std::string &key, const AnyValue &thisVal)
|
|
61
61
|
{
|
|
62
62
|
if (
|
|
63
63
|
!key.empty() && std::isdigit(static_cast<unsigned char>(key[0])) // Quick check: if the first character is not a digit, it can't be a standard index.
|
|
@@ -75,12 +75,12 @@ jspp::AnyValue jspp::JsArray::get_property(const std::string &key)
|
|
|
75
75
|
auto proto_it = ArrayPrototypes::get(key, this);
|
|
76
76
|
if (proto_it.has_value())
|
|
77
77
|
{
|
|
78
|
-
return AnyValue::resolve_property_for_read(proto_it.value());
|
|
78
|
+
return AnyValue::resolve_property_for_read(proto_it.value(), thisVal, key);
|
|
79
79
|
}
|
|
80
80
|
// not found
|
|
81
81
|
return AnyValue::make_undefined();
|
|
82
82
|
}
|
|
83
|
-
return AnyValue::resolve_property_for_read(it->second);
|
|
83
|
+
return AnyValue::resolve_property_for_read(it->second, thisVal, key);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -88,17 +88,17 @@ jspp::AnyValue jspp::JsArray::get_property(uint32_t idx)
|
|
|
88
88
|
{
|
|
89
89
|
if (idx < dense.size())
|
|
90
90
|
{
|
|
91
|
-
return
|
|
91
|
+
return dense[idx].value_or(AnyValue::make_undefined());
|
|
92
92
|
}
|
|
93
93
|
const auto &it = sparse.find(idx);
|
|
94
94
|
if (it != sparse.end())
|
|
95
95
|
{
|
|
96
|
-
return
|
|
96
|
+
return it->second.value_or(AnyValue::make_undefined());
|
|
97
97
|
}
|
|
98
98
|
return AnyValue::make_undefined();
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
jspp::AnyValue jspp::JsArray::set_property(const std::string &key, const AnyValue &value)
|
|
101
|
+
jspp::AnyValue jspp::JsArray::set_property(const std::string &key, const AnyValue &value, const AnyValue &thisVal)
|
|
102
102
|
{
|
|
103
103
|
if (
|
|
104
104
|
!key.empty() && std::isdigit(static_cast<unsigned char>(key[0])) // Quick check: if the first character is not a digit, it can't be a standard index.
|
|
@@ -114,14 +114,21 @@ jspp::AnyValue jspp::JsArray::set_property(const std::string &key, const AnyValu
|
|
|
114
114
|
if (proto_val_opt.has_value())
|
|
115
115
|
{
|
|
116
116
|
auto proto_value = proto_val_opt.value();
|
|
117
|
-
|
|
117
|
+
if (proto_value.is_accessor_descriptor())
|
|
118
|
+
{
|
|
119
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
120
|
+
}
|
|
121
|
+
if (proto_value.is_data_descriptor() && !proto_value.as_data_descriptor()->writable)
|
|
122
|
+
{
|
|
123
|
+
return AnyValue::resolve_property_for_write(proto_value, thisVal, value, key);
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
// set own property
|
|
121
128
|
auto it = props.find(key);
|
|
122
129
|
if (it != props.end())
|
|
123
130
|
{
|
|
124
|
-
return AnyValue::resolve_property_for_write(it->second, value);
|
|
131
|
+
return AnyValue::resolve_property_for_write(it->second, thisVal, value, key);
|
|
125
132
|
}
|
|
126
133
|
else
|
|
127
134
|
{
|
|
@@ -144,7 +151,8 @@ jspp::AnyValue jspp::JsArray::set_property(uint32_t idx, const AnyValue &value)
|
|
|
144
151
|
{
|
|
145
152
|
dense[idx] = AnyValue::make_undefined();
|
|
146
153
|
}
|
|
147
|
-
|
|
154
|
+
dense[idx] = value;
|
|
155
|
+
return value;
|
|
148
156
|
}
|
|
149
157
|
else if (idx <= dense.size() + DENSE_GROW_THRESHOLD)
|
|
150
158
|
{
|
|
@@ -161,7 +169,8 @@ jspp::AnyValue jspp::JsArray::set_property(uint32_t idx, const AnyValue &value)
|
|
|
161
169
|
{
|
|
162
170
|
it->second = AnyValue::make_undefined();
|
|
163
171
|
}
|
|
164
|
-
|
|
172
|
+
it->second = value;
|
|
173
|
+
return value;
|
|
165
174
|
}
|
|
166
175
|
else
|
|
167
176
|
{
|