@ugo-studio/jspp 0.2.9 → 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.
Files changed (35) hide show
  1. package/dist/core/codegen/class-handlers.js +6 -6
  2. package/dist/core/codegen/statement-handlers.js +1 -1
  3. package/package.json +1 -1
  4. package/src/prelude/any_value.hpp +362 -362
  5. package/src/prelude/any_value_access.hpp +170 -170
  6. package/src/prelude/any_value_defines.hpp +189 -189
  7. package/src/prelude/any_value_helpers.hpp +374 -374
  8. package/src/prelude/library/array.hpp +185 -185
  9. package/src/prelude/library/console.hpp +111 -111
  10. package/src/prelude/library/error.hpp +112 -112
  11. package/src/prelude/library/function.hpp +10 -10
  12. package/src/prelude/library/math.hpp +307 -307
  13. package/src/prelude/library/object.hpp +275 -275
  14. package/src/prelude/library/process.hpp +39 -39
  15. package/src/prelude/library/promise.hpp +123 -123
  16. package/src/prelude/library/symbol.hpp +52 -52
  17. package/src/prelude/library/timer.hpp +91 -91
  18. package/src/prelude/types.hpp +178 -178
  19. package/src/prelude/utils/access.hpp +411 -411
  20. package/src/prelude/utils/operators.hpp +336 -336
  21. package/src/prelude/values/array.hpp +0 -1
  22. package/src/prelude/values/async_iterator.hpp +83 -83
  23. package/src/prelude/values/function.hpp +82 -82
  24. package/src/prelude/values/helpers/array.hpp +198 -208
  25. package/src/prelude/values/helpers/async_iterator.hpp +275 -275
  26. package/src/prelude/values/helpers/function.hpp +108 -108
  27. package/src/prelude/values/helpers/iterator.hpp +144 -144
  28. package/src/prelude/values/helpers/promise.hpp +253 -253
  29. package/src/prelude/values/helpers/string.hpp +37 -61
  30. package/src/prelude/values/promise.hpp +72 -72
  31. package/src/prelude/values/prototypes/array.hpp +14 -2
  32. package/src/prelude/values/prototypes/iterator.hpp +201 -201
  33. package/src/prelude/values/prototypes/promise.hpp +196 -196
  34. package/src/prelude/values/prototypes/string.hpp +564 -542
  35. 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 = [](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
- }
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([](jspp::AnyValue thisVal, std::span<const jspp::AnyValue> args) -> jspp::AnyValue {
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");