@mentra/crust 3.3.0-dev.656 → 3.3.0-dev.658

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 (56) hide show
  1. package/README.md +7 -0
  2. package/android/build.gradle +15 -40
  3. package/android/src/main/java/com/mentra/crust/jsc/JSCRuntime.kt +13 -4
  4. package/android/src/test/java/com/mentra/crust/jsc/QuickJsLifecycleTest.kt +87 -0
  5. package/package.json +2 -2
  6. package/plugin/build/index.d.ts +2 -0
  7. package/plugin/build/index.js +2 -0
  8. package/plugin/build/withAndroid.js +39 -0
  9. package/android/quickjs-consumer-rules.pro +0 -6
  10. package/android/scripts/test-quickjs-lifecycle.py +0 -45
  11. package/android/src/main/cpp/quickjs/CMakeLists.txt +0 -20
  12. package/android/src/main/cpp/quickjs/LICENSE.quickjs-kt.txt +0 -201
  13. package/android/src/main/cpp/quickjs/README.md +0 -30
  14. package/android/src/main/cpp/quickjs/c-vector/LICENSE +0 -21
  15. package/android/src/main/cpp/quickjs/c-vector/cvector.h +0 -479
  16. package/android/src/main/cpp/quickjs/common/quickjs_version.c +0 -9
  17. package/android/src/main/cpp/quickjs/common/quickjs_version.h +0 -9
  18. package/android/src/main/cpp/quickjs/engine/LICENSE +0 -22
  19. package/android/src/main/cpp/quickjs/engine/VERSION +0 -1
  20. package/android/src/main/cpp/quickjs/engine/cutils.c +0 -631
  21. package/android/src/main/cpp/quickjs/engine/cutils.h +0 -347
  22. package/android/src/main/cpp/quickjs/engine/libbf.c +0 -8475
  23. package/android/src/main/cpp/quickjs/engine/libbf.h +0 -535
  24. package/android/src/main/cpp/quickjs/engine/libregexp-opcode.h +0 -57
  25. package/android/src/main/cpp/quickjs/engine/libregexp.c +0 -2501
  26. package/android/src/main/cpp/quickjs/engine/libregexp.h +0 -55
  27. package/android/src/main/cpp/quickjs/engine/libunicode-table.h +0 -4557
  28. package/android/src/main/cpp/quickjs/engine/libunicode.c +0 -1910
  29. package/android/src/main/cpp/quickjs/engine/libunicode.h +0 -182
  30. package/android/src/main/cpp/quickjs/engine/list.h +0 -99
  31. package/android/src/main/cpp/quickjs/engine/quickjs-atom.h +0 -273
  32. package/android/src/main/cpp/quickjs/engine/quickjs-opcode.h +0 -372
  33. package/android/src/main/cpp/quickjs/engine/quickjs.c +0 -55978
  34. package/android/src/main/cpp/quickjs/engine/quickjs.h +0 -1087
  35. package/android/src/main/cpp/quickjs/jni/binding_bridge.c +0 -488
  36. package/android/src/main/cpp/quickjs/jni/binding_bridge.h +0 -32
  37. package/android/src/main/cpp/quickjs/jni/exception_util.c +0 -64
  38. package/android/src/main/cpp/quickjs/jni/exception_util.h +0 -21
  39. package/android/src/main/cpp/quickjs/jni/jni_globals.c +0 -59
  40. package/android/src/main/cpp/quickjs/jni/jni_globals.h +0 -12
  41. package/android/src/main/cpp/quickjs/jni/jni_globals_generated.c +0 -855
  42. package/android/src/main/cpp/quickjs/jni/jni_globals_generated.h +0 -171
  43. package/android/src/main/cpp/quickjs/jni/js_value_util.c +0 -213
  44. package/android/src/main/cpp/quickjs/jni/js_value_util.h +0 -71
  45. package/android/src/main/cpp/quickjs/jni/log_util.h +0 -15
  46. package/android/src/main/cpp/quickjs/jni/mapping/jni_types_util.c +0 -27
  47. package/android/src/main/cpp/quickjs/jni/mapping/jni_types_util.h +0 -15
  48. package/android/src/main/cpp/quickjs/jni/mapping/jobject_to_js_value.c +0 -620
  49. package/android/src/main/cpp/quickjs/jni/mapping/jobject_to_js_value.h +0 -13
  50. package/android/src/main/cpp/quickjs/jni/mapping/js_value_to_jobject.c +0 -421
  51. package/android/src/main/cpp/quickjs/jni/mapping/js_value_to_jobject.h +0 -12
  52. package/android/src/main/cpp/quickjs/jni/promise_rejection_handler.c +0 -20
  53. package/android/src/main/cpp/quickjs/jni/promise_rejection_handler.h +0 -10
  54. package/android/src/main/cpp/quickjs/jni/quickjs_jni.c +0 -735
  55. package/android/src/main/cpp/quickjs/jni/quickjs_jni.h +0 -40
  56. package/android/src/testNative/QuickJsLifecycleTest.kt +0 -56
@@ -1,171 +0,0 @@
1
- /// Generated header file
2
- #ifndef QJS_KT_JNI_GLOBALS_GENERATED_H
3
- #define QJS_KT_JNI_GLOBALS_GENERATED_H
4
-
5
- #include <jni.h>
6
-
7
- jclass cls_ubyte_array(JNIEnv *env);
8
-
9
- jclass cls_short(JNIEnv *env);
10
-
11
- jclass cls_byte(JNIEnv *env);
12
-
13
- jclass cls_integer(JNIEnv *env);
14
-
15
- jclass cls_long(JNIEnv *env);
16
-
17
- jclass cls_float(JNIEnv *env);
18
-
19
- jclass cls_double(JNIEnv *env);
20
-
21
- jclass cls_boolean(JNIEnv *env);
22
-
23
- jclass cls_string(JNIEnv *env);
24
-
25
- jclass cls_object(JNIEnv *env);
26
-
27
- jclass cls_system(JNIEnv *env);
28
-
29
- jclass cls_class(JNIEnv *env);
30
-
31
- jclass cls_throwable(JNIEnv *env);
32
-
33
- jclass cls_set(JNIEnv *env);
34
-
35
- jclass cls_iterator(JNIEnv *env);
36
-
37
- jclass cls_list(JNIEnv *env);
38
-
39
- jclass cls_array_list(JNIEnv *env);
40
-
41
- jclass cls_map(JNIEnv *env);
42
-
43
- jclass cls_map_entry(JNIEnv *env);
44
-
45
- jclass cls_hash_set(JNIEnv *env);
46
-
47
- jclass cls_linked_hash_map(JNIEnv *env);
48
-
49
- jclass cls_linked_hash_set(JNIEnv *env);
50
-
51
- jclass cls_quick_js_exception(JNIEnv *env);
52
-
53
- jclass cls_quick_js(JNIEnv *env);
54
-
55
- jclass cls_memory_usage(JNIEnv *env);
56
-
57
- jclass cls_js_property(JNIEnv *env);
58
-
59
- jclass cls_js_function(JNIEnv *env);
60
-
61
- jclass cls_js_object(JNIEnv *env);
62
-
63
- jmethodID method_ubyte_array_init(JNIEnv *env);
64
-
65
- jmethodID method_short_short_value(JNIEnv *env);
66
-
67
- jmethodID method_byte_byte_value(JNIEnv *env);
68
-
69
- jmethodID method_integer_value_of(JNIEnv *env);
70
-
71
- jmethodID method_integer_int_value(JNIEnv *env);
72
-
73
- jmethodID method_long_value_of(JNIEnv *env);
74
-
75
- jmethodID method_long_long_value(JNIEnv *env);
76
-
77
- jmethodID method_float_float_value(JNIEnv *env);
78
-
79
- jmethodID method_double_value_of(JNIEnv *env);
80
-
81
- jmethodID method_double_double_value(JNIEnv *env);
82
-
83
- jmethodID method_boolean_value_of(JNIEnv *env);
84
-
85
- jmethodID method_boolean_boolean_value(JNIEnv *env);
86
-
87
- jmethodID method_object_to_string(JNIEnv *env);
88
-
89
- jmethodID method_system_identity_hash_code(JNIEnv *env);
90
-
91
- jmethodID method_class_get_name(JNIEnv *env);
92
-
93
- jmethodID method_class_is_array(JNIEnv *env);
94
-
95
- jmethodID method_throwable_get_message(JNIEnv *env);
96
-
97
- jmethodID method_throwable_get_stack_trace(JNIEnv *env);
98
-
99
- jmethodID method_set_iterator(JNIEnv *env);
100
-
101
- jmethodID method_set_add(JNIEnv *env);
102
-
103
- jmethodID method_set_contains(JNIEnv *env);
104
-
105
- jmethodID method_set_is_empty(JNIEnv *env);
106
-
107
- jmethodID method_iterator_has_next(JNIEnv *env);
108
-
109
- jmethodID method_iterator_next(JNIEnv *env);
110
-
111
- jmethodID method_list_size(JNIEnv *env);
112
-
113
- jmethodID method_list_get(JNIEnv *env);
114
-
115
- jmethodID method_list_add(JNIEnv *env);
116
-
117
- jmethodID method_array_list_init(JNIEnv *env);
118
-
119
- jmethodID method_array_list_init_with_capacity(JNIEnv *env);
120
-
121
- jmethodID method_map_entry_set(JNIEnv *env);
122
-
123
- jmethodID method_map_entry_get_key(JNIEnv *env);
124
-
125
- jmethodID method_map_entry_get_value(JNIEnv *env);
126
-
127
- jmethodID method_hash_set_init(JNIEnv *env);
128
-
129
- jmethodID method_linked_hash_map_init(JNIEnv *env);
130
-
131
- jmethodID method_linked_hash_map_put(JNIEnv *env);
132
-
133
- jmethodID method_linked_hash_set_init(JNIEnv *env);
134
-
135
- jmethodID method_linked_hash_set_add(JNIEnv *env);
136
-
137
- jmethodID method_quick_js_exception_init(JNIEnv *env);
138
-
139
- jmethodID method_quick_js_on_call_getter(JNIEnv *env);
140
-
141
- jmethodID method_quick_js_on_call_setter(JNIEnv *env);
142
-
143
- jmethodID method_quick_js_on_call_function(JNIEnv *env);
144
-
145
- jmethodID method_quick_js_set_eval_exception(JNIEnv *env);
146
-
147
- jmethodID method_quick_js_set_unhandled_promise_rejection(JNIEnv *env);
148
-
149
- jmethodID method_memory_usage_init(JNIEnv *env);
150
-
151
- jmethodID method_js_object_init(JNIEnv *env);
152
-
153
- jfieldID field_ubyte_array_storage(JNIEnv *env);
154
-
155
- jfieldID field_double_na_n(JNIEnv *env);
156
-
157
- jfieldID field_js_property_name(JNIEnv *env);
158
-
159
- jfieldID field_js_property_configurable(JNIEnv *env);
160
-
161
- jfieldID field_js_property_writable(JNIEnv *env);
162
-
163
- jfieldID field_js_property_enumerable(JNIEnv *env);
164
-
165
- jfieldID field_js_function_name(JNIEnv *env);
166
-
167
- jfieldID field_js_function_is_async(JNIEnv *env);
168
-
169
- void clear_jni_refs_cache(JNIEnv *env);
170
-
171
- #endif // QJS_KT_JNI_GLOBALS_GENERATED_H
@@ -1,213 +0,0 @@
1
- #include <stdlib.h>
2
- #include <string.h>
3
- #include "js_value_util.h"
4
- #include "log_util.h"
5
-
6
- char *js_array_join(JSContext *context, JSValue array, const char *separator) {
7
- if (!JS_IsArray(context, array) || separator == NULL) {
8
- return NULL;
9
- }
10
-
11
- JSValue js_len = JS_GetPropertyStr(context, array, "length");
12
- int64_t length;
13
- JS_ToInt64(context, &length, js_len);
14
- JS_FreeValue(context, js_len);
15
-
16
- if (length < 0) {
17
- fprintf(stderr, "Failed to get array length\n");
18
- return NULL;
19
- }
20
-
21
- if (length == 0) {
22
- char *str = malloc(1);
23
- str[0] = '\0';
24
- return str;
25
- }
26
-
27
- char **parts = malloc(sizeof(char *) * length);
28
-
29
- size_t separator_len = strlen(separator);
30
- size_t total_len = 0;
31
-
32
- for (int i = 0; i < length; i++) {
33
- JSValue element = JS_GetPropertyUint32(context, array, i);
34
- size_t len;
35
- const char *line = JS_ToCStringLen(context, &len, element);
36
- parts[i] = malloc(len + 1);
37
- strcpy(parts[i], line);
38
- JS_FreeCString(context, line);
39
- JS_FreeValue(context, element);
40
- total_len += len;
41
- if (i != length - 1) {
42
- total_len += separator_len;
43
- }
44
- }
45
-
46
- char *result = (char *) malloc(total_len + 1);
47
- if (result == NULL) {
48
- fprintf(stderr, "Memory allocation failed\n");
49
- return NULL;
50
- }
51
-
52
- size_t position = 0;
53
- for (int i = 0; i < length; ++i) {
54
- strcpy(result + position, parts[i]);
55
- position += strlen(parts[i]);
56
- if (i != length - 1) {
57
- strcpy(result + position, separator);
58
- position += separator_len;
59
- }
60
- free(parts[i]);
61
- }
62
-
63
- result[position] = '\0';
64
-
65
- return result;
66
- }
67
-
68
- void js_error_to_string(JSContext *context, JSValue error, char **out) {
69
- // Get name
70
- JSValue js_name = JS_GetPropertyStr(context, error, "name");
71
-
72
- if (JS_IsUndefined(js_name)) {
73
- // Could be arbitrary types
74
- const char *c_str = JS_ToCString(context, error);
75
- const char *str = c_str != NULL ? c_str : "<UNSUPPORTED_ERROR>";
76
- char *copy = malloc(strlen(str) + 1);
77
- strcpy(copy, str);
78
- *out = copy;
79
- if (c_str != NULL) {
80
- JS_FreeCString(context, c_str);
81
- }
82
- JS_FreeValue(context, js_name);
83
- return;
84
- }
85
-
86
- const char *c_name = JS_ToCString(context, js_name);
87
- const char *name = c_name != NULL ? c_name : "<UNKNOWN_ERROR>";
88
-
89
- // Get message
90
- JSValue js_message = JS_GetPropertyStr(context, error, "message");
91
- const char *c_message = JS_ToCString(context, js_message);
92
- const char *message = c_message != NULL ? c_message : "<NO_MESSAGE>";
93
-
94
- int name_len = strlen(name);
95
- int msg_len = strlen(message);
96
-
97
- // Get stack trace
98
- JSAtom stack_atom = JS_NewAtom(context, "stack");
99
- JSValue stack = JS_GetProperty(context, error, stack_atom);
100
- JS_FreeAtom(context, stack_atom);
101
- if (!JS_IsUndefined(stack)) {
102
- char *joined = js_array_join(context, stack, "\n");
103
- const char *stack_str = joined != NULL ? joined : JS_ToCString(context, stack);
104
-
105
- char *full_message = (char *) malloc(name_len + msg_len + strlen(stack_str) + 4);
106
- sprintf(full_message, "%s: %s\n%s", name, message, stack_str);
107
-
108
- // Free
109
- if (joined != NULL) {
110
- free((void *) stack_str);
111
- } else {
112
- JS_FreeCString(context, stack_str);
113
- }
114
-
115
- *out = full_message;
116
- } else {
117
- char *str = (char *) malloc(name_len + msg_len + 3);
118
- sprintf(str, "%s: %s", name, message);
119
- *out = str;
120
- }
121
-
122
- if (c_name != NULL) {
123
- JS_FreeCString(context, c_name);
124
- }
125
- if (c_message != NULL) {
126
- JS_FreeCString(context, c_message);
127
- }
128
- JS_FreeValue(context, js_name);
129
- JS_FreeValue(context, js_message);
130
- JS_FreeValue(context, stack);
131
- }
132
-
133
- JSValue new_simple_js_error(JSContext *context, const char *message) {
134
- return new_js_error(context, "Error", message, 0, NULL);
135
- }
136
-
137
- JSValue new_js_error(JSContext *context,
138
- const char *name,
139
- const char *message,
140
- uint32_t stack_trace_lines,
141
- const char **stack_trace) {
142
- JSValue error = JS_NewError(context);
143
-
144
- JSValue js_name = JS_NewString(context, name);
145
- JS_SetPropertyStr(context, error, "name", js_name);
146
-
147
- const char *msg = message != NULL ? message : "";
148
- JSValue js_message = JS_NewString(context, msg);
149
- JS_SetPropertyStr(context, error, "message", js_message);
150
-
151
- if (stack_trace_lines > 0 && stack_trace != NULL) {
152
- uint32_t stack_len = 0;
153
- for (int i = 0; i < stack_trace_lines; i++) {
154
- stack_len += strlen(stack_trace[i]) + 1;
155
- }
156
- char stack[stack_len + 1];
157
- stack[0] = '\0';
158
- for (int i = 0; i < stack_trace_lines; i++) {
159
- strcat(stack, stack_trace[i]);
160
- strcat(stack, "\n");
161
- }
162
- JSValue js_stack = JS_NewString(context, stack);
163
- JS_SetPropertyStr(context, error, "stack", js_stack);
164
- }
165
-
166
- return error;
167
- }
168
-
169
- int js_is_instance_of(JSContext *context, JSValue global_this, JSValue value,
170
- const char *constructor_name) {
171
- JSValue constructor = JS_GetPropertyStr(context, global_this, constructor_name);
172
- if (JS_IsUndefined(constructor)) {
173
- JS_FreeValue(context, constructor);
174
- return 0;
175
- }
176
- int result = JS_IsInstanceOf(context, value, constructor);
177
- JS_FreeValue(context, constructor);
178
- return result;
179
- }
180
-
181
- int js_is_promise(JSContext *context, JSValue value) {
182
- JSValue global_this = JS_GetGlobalObject(context);
183
- int result = js_is_promise_2(context, global_this, value);
184
- JS_FreeValue(context, global_this);
185
- return result;
186
- }
187
-
188
- int js_is_promise_2(JSContext *context, JSValue global_this, JSValue value) {
189
- return js_is_instance_of(context, global_this, value, "Promise");
190
- }
191
-
192
- int js_is_uint8array(JSContext *context, JSValue global_this, JSValue value) {
193
- return js_is_instance_of(context, global_this, value, "Uint8Array");
194
- }
195
-
196
- int js_is_int8array(JSContext *context, JSValue global_this, JSValue value) {
197
- return js_is_instance_of(context, global_this, value, "Int8Array");
198
- }
199
-
200
- int js_is_set(JSContext *context, JSValue global_this, JSValue value) {
201
- return js_is_instance_of(context, global_this, value, "Set");
202
- }
203
-
204
- int js_is_map(JSContext *context, JSValue global_this, JSValue value) {
205
- return js_is_instance_of(context, global_this, value, "Map");
206
- }
207
-
208
- JSValue js_promise_get_fulfilled_value(JSContext *context, JSValue promise) {
209
- JSValue result = JS_PromiseResult(context, promise);
210
- JSValue value = JS_GetPropertyStr(context, result, "value");
211
- JS_FreeValue(context, result);
212
- return value;
213
- }
@@ -1,71 +0,0 @@
1
- #ifndef QJS_KT_JS_VALUE_UTIL_H
2
- #define QJS_KT_JS_VALUE_UTIL_H
3
-
4
- #include "quickjs.h"
5
-
6
- /**
7
- * Join array to string.
8
- *
9
- * @return NULL if failed to join, when successful, free() is required.
10
- */
11
- char *js_array_join(JSContext *context, JSValue array, const char *separator);
12
-
13
- /**
14
- * Join the js error message and stack trace (if any).
15
- *
16
- * @param context The js context.
17
- * @param error The error js value.
18
- * @param out Destination string pointer.
19
- */
20
- void js_error_to_string(JSContext *context, JSValue error, char **out);
21
-
22
- /**
23
- * Create a js error with a message field.
24
- */
25
- JSValue new_simple_js_error(JSContext *context, const char *message);
26
-
27
- /**
28
- * Create a js error.
29
- */
30
- JSValue new_js_error(JSContext *context,
31
- const char *name,
32
- const char *message,
33
- uint32_t stack_trace_lines,
34
- const char **stack_trace);
35
-
36
- /**
37
- * Check if the js value is a Promise.
38
- */
39
- int js_is_promise(JSContext *context, JSValue value);
40
-
41
- /**
42
- * Check if the js value is a Promise.
43
- */
44
- int js_is_promise_2(JSContext *context, JSValue global_this, JSValue value);
45
-
46
- /**
47
- * Check if the js value is a Uint8Array.
48
- */
49
- int js_is_uint8array(JSContext *context, JSValue global_this, JSValue value);
50
-
51
- /**
52
- * Check if the js value is a Int8Array.
53
- */
54
- int js_is_int8array(JSContext *context, JSValue global_this, JSValue value);
55
-
56
- /**
57
- * Check if the js value is a Set.
58
- */
59
- int js_is_set(JSContext *context, JSValue global_this, JSValue value);
60
-
61
- /**
62
- * Check if the js value is a Map.
63
- */
64
- int js_is_map(JSContext *context, JSValue global_this, JSValue value);
65
-
66
- /**
67
- * Get the value of a fulfilled promise.
68
- */
69
- JSValue js_promise_get_fulfilled_value(JSContext *context, JSValue promise);
70
-
71
- #endif //QJS_KT_JS_VALUE_UTIL_H
@@ -1,15 +0,0 @@
1
- #ifndef QJS_KT_LOG_UTIL_H
2
- #define QJS_KT_LOG_UTIL_H
3
-
4
- #ifdef CONFIG_ANDROID
5
-
6
- #include <android/log.h>
7
-
8
- #define log(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, "QuickJSJni", fmt, ##__VA_ARGS__)
9
- #else
10
- #include <stdio.h>
11
-
12
- #define log(fmt, ...) printf(fmt, ##__VA_ARGS__); printf("\n")
13
- #endif
14
-
15
- #endif //QJS_KT_LOG_UTIL_H
@@ -1,27 +0,0 @@
1
- #include "jni_types_util.h"
2
- #include "jni_globals_generated.h"
3
-
4
- jobject java_boxed_boolean(JNIEnv *env, jboolean value) {
5
- jclass cls = cls_boolean(env);
6
- jmethodID method = method_boolean_value_of(env);
7
- return (*env)->CallStaticObjectMethod(env, cls, method, value);
8
- }
9
-
10
- jobject java_boxed_long(JNIEnv *env, int64_t value) {
11
- jclass cls = cls_long(env);
12
- jmethodID method = method_long_value_of(env);
13
- return (*env)->CallStaticObjectMethod(env, cls, method, value);
14
- }
15
-
16
- jobject java_boxed_double(JNIEnv *env, jdouble value) {
17
- jclass cls = cls_double(env);
18
- jmethodID method = method_double_value_of(env);
19
- return (*env)->CallStaticObjectMethod(env, cls, method, value);
20
- }
21
-
22
- jobject java_boxed_nan_double(JNIEnv *env) {
23
- jclass cls = cls_double(env);
24
- jfieldID field = field_double_na_n(env);
25
- jdouble basic = (*env)->GetStaticDoubleField(env, cls, field);
26
- return java_boxed_double(env, basic);
27
- }
@@ -1,15 +0,0 @@
1
- #ifndef QJS_KT_JNI_TYPES_UTIL_H
2
- #define QJS_KT_JNI_TYPES_UTIL_H
3
-
4
- #include <stdint.h>
5
- #include "jni.h"
6
-
7
- jobject java_boxed_boolean(JNIEnv *env, jboolean value);
8
-
9
- jobject java_boxed_long(JNIEnv *env, int64_t value);
10
-
11
- jobject java_boxed_double(JNIEnv *env, jdouble value);
12
-
13
- jobject java_boxed_nan_double(JNIEnv *env);
14
-
15
- #endif //QJS_KT_JNI_TYPES_UTIL_H