@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,113 +1,113 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "any_value.hpp"
|
|
5
|
-
|
|
6
|
-
// Declare Error variable
|
|
7
|
-
inline jspp::AnyValue Error;
|
|
8
|
-
|
|
9
|
-
// Constructor logic
|
|
10
|
-
inline auto errorConstructor = [](
|
|
11
|
-
{
|
|
12
|
-
// Access global Error to get prototype
|
|
13
|
-
jspp::AnyValue proto = Error.get_own_property("prototype");
|
|
14
|
-
|
|
15
|
-
jspp::AnyValue target = thisVal;
|
|
16
|
-
bool is_construct_call = false;
|
|
17
|
-
|
|
18
|
-
if (target.is_object())
|
|
19
|
-
{
|
|
20
|
-
auto obj = target.as_object();
|
|
21
|
-
if (!obj->proto.is_null() && !obj->proto.is_undefined() && is_strictly_equal_to_primitive(obj->proto, proto))
|
|
22
|
-
{
|
|
23
|
-
is_construct_call = true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!is_construct_call)
|
|
28
|
-
{
|
|
29
|
-
target = jspp::AnyValue::make_object_with_proto({}, proto);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
std::string name = "Error";
|
|
33
|
-
std::string message = "";
|
|
34
|
-
if (!args.empty() && !args[0].is_undefined())
|
|
35
|
-
{
|
|
36
|
-
message = args[0].to_std_string();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
target.define_data_property("message", jspp::AnyValue::make_string(message), true, false, true);
|
|
40
|
-
target.define_data_property("name", jspp::AnyValue::make_string(name), true, false, true);
|
|
41
|
-
target.define_data_property("stack", jspp::AnyValue::make_string(name + ": " + message + "\n at <unknown>"), true, false, true);
|
|
42
|
-
|
|
43
|
-
if (args.size() > 1 && args[1].is_object())
|
|
44
|
-
{
|
|
45
|
-
jspp::AnyValue cause = args[1].get_own_property("cause");
|
|
46
|
-
if (!cause.is_undefined())
|
|
47
|
-
{
|
|
48
|
-
target.define_data_property("cause", cause, true, false, true);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return target;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Static Error.isError(val) implementation
|
|
56
|
-
inline auto isErrorFn = jspp::AnyValue::make_function([](
|
|
57
|
-
{
|
|
58
|
-
if (args.empty()) return jspp::Constants::FALSE;
|
|
59
|
-
|
|
60
|
-
jspp::AnyValue val = args[0];
|
|
61
|
-
if (!val.is_object()) return jspp::Constants::FALSE;
|
|
62
|
-
|
|
63
|
-
// Check if it inherits from Error.prototype
|
|
64
|
-
// This is essentially 'instanceof Error'
|
|
65
|
-
jspp::AnyValue proto = Error.get_own_property("prototype");
|
|
66
|
-
|
|
67
|
-
// Walk prototype chain
|
|
68
|
-
if (val.is_object()) {
|
|
69
|
-
auto current = val.as_object()->proto;
|
|
70
|
-
while (!current.is_null()) {
|
|
71
|
-
if (is_strictly_equal_to_primitive(current, proto)) return jspp::Constants::TRUE;
|
|
72
|
-
if (current.is_object()) current = current.as_object()->proto;
|
|
73
|
-
else break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return jspp::Constants::FALSE; }, "isError");
|
|
78
|
-
|
|
79
|
-
// toString method for Error.prototype
|
|
80
|
-
inline auto errorToStringFn = jspp::AnyValue::make_function([](
|
|
81
|
-
{
|
|
82
|
-
std::string name = "Error";
|
|
83
|
-
std::string msg = "";
|
|
84
|
-
|
|
85
|
-
jspp::AnyValue n = thisVal.get_own_property("name");
|
|
86
|
-
if (!n.is_undefined()) name = n.to_std_string();
|
|
87
|
-
|
|
88
|
-
jspp::AnyValue m = thisVal.get_own_property("message");
|
|
89
|
-
if (!m.is_undefined()) msg = m.to_std_string();
|
|
90
|
-
|
|
91
|
-
if (name.empty() && msg.empty()) return jspp::AnyValue::make_string("Error");
|
|
92
|
-
if (name.empty()) return jspp::AnyValue::make_string(msg);
|
|
93
|
-
if (msg.empty()) return jspp::AnyValue::make_string(name);
|
|
94
|
-
|
|
95
|
-
return jspp::AnyValue::make_string(name + ": " + msg); }, "toString");
|
|
96
|
-
|
|
97
|
-
// Initialize Error class and its prototype
|
|
98
|
-
struct ErrorInit
|
|
99
|
-
{
|
|
100
|
-
ErrorInit()
|
|
101
|
-
{
|
|
102
|
-
// Initialize Error class
|
|
103
|
-
Error = jspp::AnyValue::make_class(errorConstructor, "Error");
|
|
104
|
-
|
|
105
|
-
// Define Error.prototype.toString
|
|
106
|
-
auto proto = Error.get_own_property("prototype");
|
|
107
|
-
proto.define_data_property("toString", errorToStringFn, true, false, true);
|
|
108
|
-
proto.define_data_property(jspp::WellKnownSymbols::toStringTag->key, errorToStringFn, true, false, true);
|
|
109
|
-
|
|
110
|
-
// Define static Error.isError
|
|
111
|
-
Error.define_data_property("isError", isErrorFn, true, false, true);
|
|
112
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
|
|
6
|
+
// Declare Error variable
|
|
7
|
+
inline jspp::AnyValue Error;
|
|
8
|
+
|
|
9
|
+
// Constructor logic
|
|
10
|
+
inline auto errorConstructor = [](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
11
|
+
{
|
|
12
|
+
// Access global Error to get prototype
|
|
13
|
+
jspp::AnyValue proto = Error.get_own_property("prototype");
|
|
14
|
+
|
|
15
|
+
jspp::AnyValue target = thisVal;
|
|
16
|
+
bool is_construct_call = false;
|
|
17
|
+
|
|
18
|
+
if (target.is_object())
|
|
19
|
+
{
|
|
20
|
+
auto obj = target.as_object();
|
|
21
|
+
if (!obj->proto.is_null() && !obj->proto.is_undefined() && is_strictly_equal_to_primitive(obj->proto, proto))
|
|
22
|
+
{
|
|
23
|
+
is_construct_call = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!is_construct_call)
|
|
28
|
+
{
|
|
29
|
+
target = jspp::AnyValue::make_object_with_proto({}, proto);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
std::string name = "Error";
|
|
33
|
+
std::string message = "";
|
|
34
|
+
if (!args.empty() && !args[0].is_undefined())
|
|
35
|
+
{
|
|
36
|
+
message = args[0].to_std_string();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
target.define_data_property("message", jspp::AnyValue::make_string(message), true, false, true);
|
|
40
|
+
target.define_data_property("name", jspp::AnyValue::make_string(name), true, false, true);
|
|
41
|
+
target.define_data_property("stack", jspp::AnyValue::make_string(name + ": " + message + "\n at <unknown>"), true, false, true);
|
|
42
|
+
|
|
43
|
+
if (args.size() > 1 && args[1].is_object())
|
|
44
|
+
{
|
|
45
|
+
jspp::AnyValue cause = args[1].get_own_property("cause");
|
|
46
|
+
if (!cause.is_undefined())
|
|
47
|
+
{
|
|
48
|
+
target.define_data_property("cause", cause, true, false, true);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return target;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Static Error.isError(val) implementation
|
|
56
|
+
inline auto isErrorFn = jspp::AnyValue::make_function([](jspp::AnyValue, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
57
|
+
{
|
|
58
|
+
if (args.empty()) return jspp::Constants::FALSE;
|
|
59
|
+
|
|
60
|
+
jspp::AnyValue val = args[0];
|
|
61
|
+
if (!val.is_object()) return jspp::Constants::FALSE;
|
|
62
|
+
|
|
63
|
+
// Check if it inherits from Error.prototype
|
|
64
|
+
// This is essentially 'instanceof Error'
|
|
65
|
+
jspp::AnyValue proto = Error.get_own_property("prototype");
|
|
66
|
+
|
|
67
|
+
// Walk prototype chain
|
|
68
|
+
if (val.is_object()) {
|
|
69
|
+
auto current = val.as_object()->proto;
|
|
70
|
+
while (!current.is_null()) {
|
|
71
|
+
if (is_strictly_equal_to_primitive(current, proto)) return jspp::Constants::TRUE;
|
|
72
|
+
if (current.is_object()) current = current.as_object()->proto;
|
|
73
|
+
else break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return jspp::Constants::FALSE; }, "isError");
|
|
78
|
+
|
|
79
|
+
// toString method for Error.prototype
|
|
80
|
+
inline auto errorToStringFn = jspp::AnyValue::make_function([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue
|
|
81
|
+
{
|
|
82
|
+
std::string name = "Error";
|
|
83
|
+
std::string msg = "";
|
|
84
|
+
|
|
85
|
+
jspp::AnyValue n = thisVal.get_own_property("name");
|
|
86
|
+
if (!n.is_undefined()) name = n.to_std_string();
|
|
87
|
+
|
|
88
|
+
jspp::AnyValue m = thisVal.get_own_property("message");
|
|
89
|
+
if (!m.is_undefined()) msg = m.to_std_string();
|
|
90
|
+
|
|
91
|
+
if (name.empty() && msg.empty()) return jspp::AnyValue::make_string("Error");
|
|
92
|
+
if (name.empty()) return jspp::AnyValue::make_string(msg);
|
|
93
|
+
if (msg.empty()) return jspp::AnyValue::make_string(name);
|
|
94
|
+
|
|
95
|
+
return jspp::AnyValue::make_string(name + ": " + msg); }, "toString");
|
|
96
|
+
|
|
97
|
+
// Initialize Error class and its prototype
|
|
98
|
+
struct ErrorInit
|
|
99
|
+
{
|
|
100
|
+
ErrorInit()
|
|
101
|
+
{
|
|
102
|
+
// Initialize Error class
|
|
103
|
+
Error = jspp::AnyValue::make_class(errorConstructor, "Error");
|
|
104
|
+
|
|
105
|
+
// Define Error.prototype.toString
|
|
106
|
+
auto proto = Error.get_own_property("prototype");
|
|
107
|
+
proto.define_data_property("toString", errorToStringFn, true, false, true);
|
|
108
|
+
proto.define_data_property(jspp::WellKnownSymbols::toStringTag->key, errorToStringFn, true, false, true);
|
|
109
|
+
|
|
110
|
+
// Define static Error.isError
|
|
111
|
+
Error.define_data_property("isError", isErrorFn, true, false, true);
|
|
112
|
+
}
|
|
113
113
|
} errorInit;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include "any_value.hpp"
|
|
5
|
-
|
|
6
|
-
// Define Function constructor
|
|
7
|
-
// In a full implementation, this would support 'new Function(args, body)'
|
|
8
|
-
inline auto Function = jspp::AnyValue::make_class([](
|
|
9
|
-
return jspp::Constants::UNDEFINED;
|
|
10
|
-
}, "Function");
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include "any_value.hpp"
|
|
5
|
+
|
|
6
|
+
// Define Function constructor
|
|
7
|
+
// In a full implementation, this would support 'new Function(args, body)'
|
|
8
|
+
inline auto Function = jspp::AnyValue::make_class([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue {
|
|
9
|
+
return jspp::Constants::UNDEFINED;
|
|
10
|
+
}, "Function");
|