Compare commits
7 Commits
serialize_
...
console
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d029037b01 | ||
|
|
ed7dd91c3f | ||
|
|
3abe20fee0 | ||
|
|
a92a96118e | ||
|
|
ab74cdc173 | ||
|
|
2c9d039271 | ||
|
|
d4635f2a75 |
@@ -125,12 +125,8 @@ JSValue js_wota_use(JSContext *js);
|
||||
void script_startup(cell_rt *prt)
|
||||
{
|
||||
JSRuntime *rt = JS_NewRuntime();
|
||||
JSContext *js = JS_NewContextRaw(rt);
|
||||
JS_SetInterruptHandler(rt, (JSInterruptHandler *)actor_interrupt_cb, prt);
|
||||
|
||||
JS_AddIntrinsicBaseObjects(js);
|
||||
JS_AddIntrinsicEval(js);
|
||||
JS_AddIntrinsicRegExp(js);
|
||||
JSContext *js = JS_NewContext(rt);
|
||||
|
||||
JS_SetContextOpaque(js, prt);
|
||||
prt->context = js;
|
||||
@@ -214,15 +210,13 @@ static int run_test_suite(size_t heap_size)
|
||||
return 1;
|
||||
}
|
||||
|
||||
JSContext *ctx = JS_NewContextRawWithHeapSize(rt, heap_size);
|
||||
JSContext *ctx = JS_NewContextWithHeapSize(rt, heap_size);
|
||||
if (!ctx) {
|
||||
printf("Failed to create JS context\n");
|
||||
JS_FreeRuntime(rt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
JS_AddIntrinsicBaseObjects(ctx);
|
||||
|
||||
int result = run_c_test_suite(ctx);
|
||||
|
||||
JS_FreeContext(ctx);
|
||||
@@ -272,7 +266,7 @@ static int run_eval(const char *script_or_file, int print_bytecode, int use_boot
|
||||
return 1;
|
||||
}
|
||||
|
||||
JSContext *ctx = JS_NewContextRaw(rt);
|
||||
JSContext *ctx = JS_NewContext(rt);
|
||||
if (!ctx) {
|
||||
printf("Failed to create JS context\n");
|
||||
JS_FreeRuntime(rt);
|
||||
@@ -280,10 +274,6 @@ static int run_eval(const char *script_or_file, int print_bytecode, int use_boot
|
||||
return 1;
|
||||
}
|
||||
|
||||
JS_AddIntrinsicBaseObjects(ctx);
|
||||
JS_AddIntrinsicEval(ctx);
|
||||
JS_AddIntrinsicRegExp(ctx);
|
||||
|
||||
int result = 0;
|
||||
|
||||
JSGCRef bytecode_ref;
|
||||
|
||||
1278
source/quickjs.c
1278
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -176,8 +176,6 @@ void JS_DeleteGCRef(JSContext *ctx, JSGCRef *ref);
|
||||
Value Extraction
|
||||
============================================================ */
|
||||
|
||||
#define JS_VALUE_GET_INT(v) ((int)(v) >> 1)
|
||||
|
||||
/* Get primary tag (low 2-3 bits) */
|
||||
static inline int
|
||||
JS_VALUE_GET_TAG (JSValue v) {
|
||||
@@ -334,13 +332,8 @@ JS_IsShortFloat (JSValue v) {
|
||||
#define JS_DEFAULT_STACK_SIZE (1024 * 1024)
|
||||
#endif
|
||||
|
||||
/* Internal eval flags */
|
||||
#define JS_EVAL_TYPE_GLOBAL (0 << 0) /* global code (default) */
|
||||
#define JS_EVAL_TYPE_DIRECT (2 << 0) /* direct call (internal use) */
|
||||
#define JS_EVAL_TYPE_INDIRECT (3 << 0) /* indirect call (internal use) */
|
||||
#define JS_EVAL_TYPE_MASK (3 << 0)
|
||||
/* Internal compile flags */
|
||||
#define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5) /* internal use */
|
||||
#define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6) /* internal use */
|
||||
|
||||
typedef JSValue JSCFunction (JSContext *ctx, JSValue this_val, int argc,
|
||||
JSValue *argv);
|
||||
@@ -395,10 +388,7 @@ JSRuntime *JS_GetRuntime (JSContext *ctx);
|
||||
void JS_SetClassProto (JSContext *ctx, JSClassID class_id, JSValue obj);
|
||||
JSValue JS_GetClassProto (JSContext *ctx, JSClassID class_id);
|
||||
|
||||
/* the following functions are used to select the intrinsic object to
|
||||
save memory */
|
||||
JSContext *JS_NewContextRaw (JSRuntime *rt);
|
||||
JSContext *JS_NewContextRawWithHeapSize (JSRuntime *rt, size_t heap_size);
|
||||
JSContext *JS_NewContextWithHeapSize (JSRuntime *rt, size_t heap_size);
|
||||
|
||||
typedef struct JSMemoryUsage {
|
||||
int64_t malloc_size, malloc_limit, memory_used_size;
|
||||
@@ -733,7 +723,6 @@ JSValue JS_Compile (JSContext *ctx, const char *input, size_t input_len,
|
||||
env should be stoned record or null.
|
||||
Variables resolve: env first, then global intrinsics. */
|
||||
JSValue JS_Integrate (JSContext *ctx, JSValue bytecode, JSValue env);
|
||||
JSValue JS_GetGlobalObject (JSContext *ctx);
|
||||
void JS_SetOpaque (JSValue obj, void *opaque);
|
||||
void *JS_GetOpaque (JSValue obj, JSClassID class_id);
|
||||
void *JS_GetOpaque2 (JSContext *ctx, JSValue obj, JSClassID class_id);
|
||||
@@ -793,7 +782,14 @@ typedef enum JSCFunctionEnum {
|
||||
JS_CFUNC_1, /* JSValue f(ctx, this_val, arg0) */
|
||||
JS_CFUNC_2, /* JSValue f(ctx, this_val, arg0, arg1) */
|
||||
JS_CFUNC_3, /* JSValue f(ctx, this_val, arg0, arg1, arg2) */
|
||||
JS_CFUNC_4
|
||||
JS_CFUNC_4,
|
||||
/* Pure functions (no this_val) - for global utility functions */
|
||||
JS_CFUNC_PURE, /* JSValue f(ctx, argc, argv) - generic pure */
|
||||
JS_CFUNC_PURE_0, /* JSValue f(ctx) */
|
||||
JS_CFUNC_PURE_1, /* JSValue f(ctx, arg0) */
|
||||
JS_CFUNC_PURE_2, /* JSValue f(ctx, arg0, arg1) */
|
||||
JS_CFUNC_PURE_3, /* JSValue f(ctx, arg0, arg1, arg2) */
|
||||
JS_CFUNC_PURE_4 /* JSValue f(ctx, arg0, arg1, arg2, arg3) */
|
||||
} JSCFunctionEnum;
|
||||
|
||||
/* Fixed-arity C function types for fast paths */
|
||||
@@ -809,6 +805,16 @@ typedef JSValue JSCFunction4 (JSContext *ctx, JSValue this_val,
|
||||
JSValue arg0, JSValue arg1,
|
||||
JSValue arg2, JSValue arg3);
|
||||
|
||||
/* Pure function types (no this_val) */
|
||||
typedef JSValue JSCFunctionPure (JSContext *ctx, int argc, JSValue *argv);
|
||||
typedef JSValue JSCFunctionPure0 (JSContext *ctx);
|
||||
typedef JSValue JSCFunctionPure1 (JSContext *ctx, JSValue arg0);
|
||||
typedef JSValue JSCFunctionPure2 (JSContext *ctx, JSValue arg0, JSValue arg1);
|
||||
typedef JSValue JSCFunctionPure3 (JSContext *ctx, JSValue arg0, JSValue arg1,
|
||||
JSValue arg2);
|
||||
typedef JSValue JSCFunctionPure4 (JSContext *ctx, JSValue arg0, JSValue arg1,
|
||||
JSValue arg2, JSValue arg3);
|
||||
|
||||
typedef union JSCFunctionType {
|
||||
JSCFunction *generic;
|
||||
JSValue (*generic_magic) (JSContext *ctx, JSValue this_val, int argc,
|
||||
@@ -821,6 +827,13 @@ typedef union JSCFunctionType {
|
||||
JSCFunction2 *f2;
|
||||
JSCFunction3 *f3;
|
||||
JSCFunction4 *f4;
|
||||
/* Pure function pointers */
|
||||
JSCFunctionPure *pure;
|
||||
JSCFunctionPure0 *pure0;
|
||||
JSCFunctionPure1 *pure1;
|
||||
JSCFunctionPure2 *pure2;
|
||||
JSCFunctionPure3 *pure3;
|
||||
JSCFunctionPure4 *pure4;
|
||||
} JSCFunctionType;
|
||||
|
||||
JSValue JS_NewCFunction2 (JSContext *ctx, JSCFunction *func, const char *name,
|
||||
@@ -937,6 +950,43 @@ typedef struct JSCFunctionListEntry {
|
||||
.u \
|
||||
= {.func = { 3, JS_CFUNC_3, { .f3 = func1 } } } \
|
||||
}
|
||||
/* Pure function (no this_val) macros */
|
||||
#define JS_CFUNC_PURE_DEF(name, length, func1) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, 0, \
|
||||
.u \
|
||||
= {.func = { length, JS_CFUNC_PURE, { .pure = func1 } } } \
|
||||
}
|
||||
#define JS_CFUNC_PURE0_DEF(name, func1) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, 0, \
|
||||
.u \
|
||||
= {.func = { 0, JS_CFUNC_PURE_0, { .pure0 = func1 } } } \
|
||||
}
|
||||
#define JS_CFUNC_PURE1_DEF(name, func1) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, 0, \
|
||||
.u \
|
||||
= {.func = { 1, JS_CFUNC_PURE_1, { .pure1 = func1 } } } \
|
||||
}
|
||||
#define JS_CFUNC_PURE2_DEF(name, func1) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, 0, \
|
||||
.u \
|
||||
= {.func = { 2, JS_CFUNC_PURE_2, { .pure2 = func1 } } } \
|
||||
}
|
||||
#define JS_CFUNC_PURE3_DEF(name, func1) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, 0, \
|
||||
.u \
|
||||
= {.func = { 3, JS_CFUNC_PURE_3, { .pure3 = func1 } } } \
|
||||
}
|
||||
#define JS_CFUNC_PURE4_DEF(name, func1) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, 0, \
|
||||
.u \
|
||||
= {.func = { 4, JS_CFUNC_PURE_4, { .pure4 = func1 } } } \
|
||||
}
|
||||
#define JS_ITERATOR_NEXT_DEF(name, length, func1, magic) \
|
||||
{ \
|
||||
name, 0, JS_DEF_CFUNC, magic, .u = { \
|
||||
@@ -1049,12 +1099,6 @@ void *js_malloc_rt (size_t size);
|
||||
void *js_mallocz_rt (size_t size);
|
||||
void js_free_rt (void *ptr);
|
||||
|
||||
/* Intrinsic setup functions */
|
||||
void JS_AddIntrinsicBaseObjects (JSContext *ctx);
|
||||
void JS_AddIntrinsicBasicObjects (JSContext *ctx);
|
||||
void JS_AddIntrinsicEval (JSContext *ctx);
|
||||
void JS_AddIntrinsicRegExp (JSContext *ctx);
|
||||
|
||||
#undef js_unlikely
|
||||
#undef inline
|
||||
|
||||
|
||||
@@ -954,24 +954,6 @@ TEST(array_foreach_basic) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
GLOBAL OBJECT TEST
|
||||
============================================================================ */
|
||||
|
||||
TEST(global_object) {
|
||||
JSGCRef global_ref;
|
||||
JS_PushGCRef(ctx, &global_ref);
|
||||
global_ref.val = JS_GetGlobalObject(ctx);
|
||||
ASSERT(JS_IsRecord(global_ref.val));
|
||||
|
||||
/* Set something on global */
|
||||
JS_SetPropertyStr(ctx, global_ref.val, "testGlobal", JS_NewInt32(ctx, 777));
|
||||
JSValue val = JS_GetPropertyStr(ctx, global_ref.val, "testGlobal");
|
||||
JS_PopGCRef(ctx, &global_ref);
|
||||
ASSERT_INT(val, 777);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
VALUE CONVERSION TESTS
|
||||
============================================================================ */
|
||||
@@ -1521,23 +1503,6 @@ TEST(new_cfunction_with_args) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(call_function_on_global) {
|
||||
JSGCRef func_ref, global_ref;
|
||||
JS_PushGCRef(ctx, &global_ref);
|
||||
JS_PushGCRef(ctx, &func_ref);
|
||||
global_ref.val = JS_GetGlobalObject(ctx);
|
||||
func_ref.val = JS_NewCFunction(ctx, cfunc_return_42, "testFunc", 0);
|
||||
JS_SetPropertyStr(ctx, global_ref.val, "testFunc", func_ref.val);
|
||||
JSValue got = JS_GetPropertyStr(ctx, global_ref.val, "testFunc");
|
||||
int is_func = JS_IsFunction(got);
|
||||
JSValue result = JS_Call(ctx, got, JS_NULL, 0, NULL);
|
||||
JS_PopGCRef(ctx, &func_ref);
|
||||
JS_PopGCRef(ctx, &global_ref);
|
||||
ASSERT(is_func);
|
||||
ASSERT_INT(result, 42);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
PROPERTY ACCESS TESTS
|
||||
============================================================================ */
|
||||
@@ -2113,9 +2078,6 @@ int run_c_test_suite(JSContext *ctx)
|
||||
RUN_TEST(strict_eq_null);
|
||||
RUN_TEST(strict_eq_bool);
|
||||
|
||||
printf("\nGlobal Object:\n");
|
||||
RUN_TEST(global_object);
|
||||
|
||||
printf("\nValue Conversions:\n");
|
||||
RUN_TEST(to_bool_true_values);
|
||||
RUN_TEST(to_bool_false_values);
|
||||
@@ -2188,7 +2150,6 @@ int run_c_test_suite(JSContext *ctx)
|
||||
printf("\nC Functions:\n");
|
||||
RUN_TEST(new_cfunction_no_args);
|
||||
RUN_TEST(new_cfunction_with_args);
|
||||
RUN_TEST(call_function_on_global);
|
||||
|
||||
printf("\nProperty Access:\n");
|
||||
RUN_TEST(get_property_with_jsvalue_key);
|
||||
|
||||
Reference in New Issue
Block a user