int test_1(duk_context *ctx) { int i, n; duk_set_top(ctx, 0); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_object(ctx); duk_push_thread(ctx); n = duk_get_top(ctx); printf("top: %d\n", n); for (i = 0; i < n; i++) { int t; duk_to_object(ctx, i); t = duk_get_type(ctx, i); duk_to_string(ctx, i); printf("index %d, type: %d, string coerced: %s\n", i, t, duk_to_string(ctx, i)); } return 0; }
void rtDukContext::clonedEnvironment(rtDukContextRef clone_me) { rtLogInfo(__FUNCTION__); duk_idx_t thr_idx = duk_push_thread(clone_me->dukCtx); duk_dup(clone_me->dukCtx, -1); rtScriptDukUtils::rtDukPutIdentToGlobal(clone_me->dukCtx); dukCtx = duk_get_context(clone_me->dukCtx, thr_idx); uv_loop_t *dukLoop = new uv_loop_t(); uv_loop_init(dukLoop); dukLoop->data = dukCtx; uvLoop = dukLoop; { duk_push_thread_stash(dukCtx, dukCtx); duk_push_pointer(dukCtx, (void*)dukLoop); duk_bool_t rc = duk_put_prop_string(dukCtx, -2, "__duk_loop"); assert(rc); duk_pop(dukCtx); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
int test_1(duk_context *ctx) { int i, n; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_object(ctx); duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); duk_push_fixed_buffer(ctx, 1024); duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeef); n = duk_get_top(ctx); printf("top: %d\n", n); for (i = 0; i < n; i++) { duk_to_undefined(ctx, i); printf("index %d, is-undefined: %d\n", i, duk_is_undefined(ctx, i)); } return 0; }
static duk_ret_t test_2a(duk_context *ctx, void *udata) { (void) udata; /* Test first with nothing on stack index -3. */ duk_safe_call(ctx, test__null, NULL, 0, 1); printf("%s\n", duk_safe_to_string(ctx, 0)); duk_pop(ctx); duk_set_top(ctx, 0); duk_push_undefined(ctx); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_null(ctx); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_true(ctx); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_false(ctx); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_number(ctx, 123.0); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_string(ctx, "foo\x00" "bar"); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_fixed_buffer(ctx, 16); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_pointer(ctx, NULL); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_pointer(ctx, (void *) 0xdeadbeefUL); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_object(ctx); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_array(ctx); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_c_function(ctx, dummy_func, 0); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_c_lightfunc(ctx, dummy_func, 0, 0, 0); test__require_calls(ctx); duk_set_top(ctx, 0); duk_eval_string(ctx, "(function dummy(){})"); test__require_calls(ctx); duk_set_top(ctx, 0); duk_push_thread(ctx); test__require_calls(ctx); printf("done\n"); return 0; }
/* Thread with shared and fresh globals. */ static duk_ret_t test_2(duk_context *ctx, void *udata) { duk_context *ctx_a; duk_context *ctx_b; (void) udata; duk_eval_string_noresult(ctx, "this.globalFoo = 'bar';"); duk_push_thread(ctx); ctx_a = duk_require_context(ctx, -1); duk_push_thread_new_globalenv(ctx); ctx_b = duk_require_context(ctx, -1); printf("top: %ld\n", (long) duk_get_top(ctx)); /* Dummy print() binding. */ duk_push_c_function(ctx_b, my_print, 1); duk_put_global_string(ctx_b, "print"); /* index 0: thread with globals shared with 'ctx' (has globalFoo) * index 1: thread with globals separate with 'ctx' */ /* Print globalFoo. */ duk_peval_string_noresult(ctx_a, "print('context a: ' + String(this.globalFoo));"); duk_peval_string_noresult(ctx_b, "print('context b: ' + String(this.globalFoo));"); return 0; }
/* Some basic tests. */ static duk_ret_t test_1(duk_context *ctx, void *udata) { duk_idx_t thr_idx; duk_context *new_ctx; (void) udata; duk_push_int(ctx, 123); /* dummy */ thr_idx = duk_push_thread(ctx); printf("duk_is_object(%ld) = %d\n", (long) thr_idx, (int) duk_is_object(ctx, thr_idx)); printf("duk_is_thread(%ld) = %d\n", (long) thr_idx, (int) duk_is_thread(ctx, thr_idx)); printf("top=%ld\n", (long) duk_get_top(ctx)); /* use the thread (context) value stack */ new_ctx = duk_get_context(ctx, thr_idx); duk_push_string(new_ctx, "foo"); duk_push_string(new_ctx, "bar"); duk_push_string(new_ctx, "quux"); duk_concat(new_ctx, 3); printf("concat: %s\n", duk_get_string(new_ctx, -1)); /* make new thread unreachable, so it gets GC'd */ duk_set_top(ctx, 0); printf("done\n"); return 0; }
static duk_ret_t test_1(duk_context *ctx, void *udata) { duk_idx_t i, n; (void) udata; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_object(ctx); duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); duk_push_fixed_buffer(ctx, 1024); duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeef); n = duk_get_top(ctx); printf("top: %ld\n", (long) n); for (i = 0; i < n; i++) { duk_to_null(ctx, i); printf("index %ld, is-null: %d\n", (long) i, (int) duk_is_null(ctx, i)); } return 0; }
static duk_ret_t test_suspend_resume_reterr_basic(duk_context *ctx, void *udata) { duk_context *other; duk_thread_state st; (void) duk_push_thread(ctx); other = duk_get_context(ctx, -1); duk_suspend(ctx, &st); duk_eval_string(other, "try { throw 'other thread executing'; } catch (e) { print(e); }"); duk_resume(ctx, &st); return DUK_RET_RANGE_ERROR; }
static duk_ret_t test_1(duk_context *ctx, void *udata) { duk_idx_t i, n; (void) udata; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 1); duk_push_number(ctx, -123.456); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_string(ctx, "123"); duk_push_string(ctx, "123.456"); duk_push_string(ctx, "123.456e3"); duk_push_string(ctx, " -123.456e+3 "); duk_push_string(ctx, "NaN"); duk_push_string(ctx, "-Infinity"); duk_push_string(ctx, "+Infinity"); duk_push_string(ctx, "Infinity"); duk_push_string(ctx, "Infinityx"); duk_push_string(ctx, "xInfinity"); duk_push_string(ctx, " Infinity "); duk_push_object(ctx); duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); /* coerces like string: ToNumber('') = 0 */ duk_push_fixed_buffer(ctx, 1024); /* coerces like string: ToNumber('\u0000\u0000...') = NaN */ duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeefUL); n = duk_get_top(ctx); printf("top: %ld\n", (long) n); for (i = 0; i < n; i++) { printf("index %ld, number: %lf\n", (long) i, (double) duk_to_number(ctx, i)); } return 0; }
static duk_ret_t test_suspend_resume_throw_basic(duk_context *ctx, void *udata) { duk_context *other; duk_thread_state st; (void) duk_push_thread(ctx); other = duk_get_context(ctx, -1); duk_suspend(ctx, &st); duk_eval_string(other, "print('other thread executing');"); duk_resume(ctx, &st); (void) duk_range_error(ctx, "aiee"); duk_pop(ctx); printf("final top: %ld\n", (long) duk_get_top(ctx)); return 0; }
static duk_ret_t test_1(duk_context *ctx, void *udata) { duk_idx_t i, n; (void) udata; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_object(ctx); duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); duk_push_fixed_buffer(ctx, 1024); duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeefUL); n = duk_get_top(ctx); printf("top: %ld\n", (long) n); for (i = 0; i < n; i++) { void *ptr; duk_int_t t1, t2; t1 = duk_get_type(ctx, i); ptr = duk_to_pointer(ctx, i); t2 = duk_get_type(ctx, i); printf("index %ld, ptr-is-NULL: %d, type: %ld -> %ld\n", (long) i, (ptr == NULL ? 1 : 0), (long) t1, (long) t2); if (t1 == DUK_TYPE_POINTER) { /* check that pointer is retained as is (can safely print) */ printf("pointer: %p\n", ptr); } } return 0; }
static duk_ret_t test_1(duk_context *ctx, void *udata) { duk_idx_t i, n; (void) udata; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_object(ctx); duk_push_number(ctx, 123.456); duk_to_object(ctx, -1); /* Number(123.456) */ duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); duk_push_fixed_buffer(ctx, 1024); duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeef); n = duk_get_top(ctx); printf("top: %ld\n", (long) n); for (i = 0; i < n; i++) { duk_int_t t1, t2; t1 = duk_get_type(ctx, i); duk_to_primitive(ctx, i, DUK_HINT_NONE); t2 = duk_get_type(ctx, i); printf("index %ld, ToString(result): '%s', type: %ld -> %ld\n", (long) i, duk_to_string(ctx, i), (long) t1, (long) t2); } return 0; }
static duk_ret_t test_1(duk_context *ctx) { duk_context *new_ctx; duk_set_top(ctx, 0); (void) duk_push_thread(ctx); new_ctx = duk_get_context(ctx, -1); duk_push_string(new_ctx, "foo"); duk_push_string(new_ctx, "bar"); duk_push_string(new_ctx, "quux"); duk_concat(new_ctx, 3); printf("concat: %s\n", duk_get_string(new_ctx, -1)); /* This duk_pop() makes the new thread unreachable (assuming there * is no other reference to it), so new_ctx is no longer valid * afterwards. */ duk_pop(ctx); printf("still here\n"); return 0; }
duk_ret_t duk_bi_thread_constructor(duk_context *ctx) { duk_hthread *new_thr; duk_hobject *func; if (!duk_is_callable(ctx, 0)) { return DUK_RET_TYPE_ERROR; } func = duk_get_hobject(ctx, 0); DUK_ASSERT(func != NULL); duk_push_thread(ctx); new_thr = (duk_hthread *) duk_get_hobject(ctx, -1); DUK_ASSERT(new_thr != NULL); new_thr->state = DUK_HTHREAD_STATE_INACTIVE; /* push initial function call to new thread stack; this is * picked up by resume(). */ duk_push_hobject((duk_context *) new_thr, func); return 1; /* return thread */ }
/* Thread with shared and fresh globals. */ static int test_2(duk_context *ctx) { duk_context *ctx_a; duk_context *ctx_b; duk_eval_string_noresult(ctx, "this.globalFoo = 'bar';"); duk_push_thread(ctx); ctx_a = duk_require_context(ctx, -1); duk_push_thread_new_globalenv(ctx); ctx_b = duk_require_context(ctx, -1); printf("top: %d\n", duk_get_top(ctx)); /* index 0: thread with globals shared with 'ctx' (has globalFoo) * index 1: thread with globals separate with 'ctx' */ /* Print globalFoo. */ duk_peval_string_noresult(ctx_a, "print('context a: ' + String(this.globalFoo));"); duk_peval_string_noresult(ctx_b, "print('context b: ' + String(this.globalFoo));"); return 0; }
int test_1(duk_context *ctx) { int i, n; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_number(ctx, 123.456); duk_push_number(ctx, -123.456); duk_push_number(ctx, 123.999); duk_push_number(ctx, -123.999); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_string(ctx, "123"); duk_push_string(ctx, "123.456"); duk_push_string(ctx, "123.456e3"); duk_push_string(ctx, " -123.456e+3 "); duk_push_string(ctx, "NaN"); duk_push_string(ctx, "-Infinity"); duk_push_string(ctx, "+Infinity"); duk_push_string(ctx, "Infinity"); duk_push_string(ctx, "Infinityx"); duk_push_string(ctx, "xInfinity"); duk_push_string(ctx, " Infinity "); duk_push_object(ctx); duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); duk_push_fixed_buffer(ctx, 1024); duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeef); n = duk_get_top(ctx); printf("top: %d\n", n); for (i = 0; i < n; i++) { double dval_pre; double dval_post; int ival; dval_pre = duk_get_number(ctx, i); /* number before ToInteger() coercion */ ival = duk_to_int(ctx, i); dval_post = duk_get_number(ctx, i); /* number after ToInteger() coercion */ printf("index %d, ", i); if (ival == INT_MIN) { printf("int: INT_MIN"); } else if (ival == INT_MAX) { printf("int: INT_MAX"); } else { printf("int: %d", ival); } printf(", number before: %lf, number after: %lf\n", dval_pre, dval_post); } return 0; }
void test(duk_context *ctx) { duk_idx_t i, n; /* * push test values */ /* 0 */ duk_push_undefined(ctx); /* 1 */ duk_push_null(ctx); /* 2 */ duk_push_true(ctx); /* 3 */ duk_push_false(ctx); /* 4 */ duk_push_int(ctx, 123); /* 5 */ duk_push_number(ctx, 123.4); /* 6 */ duk_push_nan(ctx); /* 7 */ duk_push_number(ctx, INFINITY); /* 8 */ duk_push_number(ctx, -INFINITY); /* 9 */ duk_push_string(ctx, ""); /* 10 */ duk_push_string(ctx, "foo"); /* 11 */ duk_push_object(ctx); /* 12 */ duk_push_array(ctx); /* 13 */ duk_push_c_function(ctx, my_c_func, DUK_VARARGS); /* 14 */ duk_push_string(ctx, "(function() { print('hello'); })"); duk_eval(ctx); /* 15 */ duk_push_string(ctx, "escape.bind(null, 'foo')"); duk_eval(ctx); /* 16 */ duk_push_thread(ctx); /* 17 */ duk_push_buffer(ctx, 1024, 0 /*dynamic*/); /* 18 */ duk_push_buffer(ctx, 1024, 1 /*dynamic*/); /* 19 */ duk_push_pointer(ctx, (void *) 0xf00); /* * call checkers for each */ n = duk_get_top(ctx); for (i = 0; i < n; i++) { printf("%02ld: ", (long) i); printf(" und=%d", (int) duk_is_undefined(ctx, i)); printf(" null=%d", (int) duk_is_null(ctx, i)); printf(" noru=%d", (int) duk_is_null_or_undefined(ctx, i)); printf(" bool=%d", (int) duk_is_boolean(ctx, i)); printf(" num=%d", (int) duk_is_number(ctx, i)); printf(" nan=%d", (int) duk_is_nan(ctx, i)); printf(" str=%d", (int) duk_is_string(ctx, i)); printf(" obj=%d", (int) duk_is_object(ctx, i)); printf(" arr=%d", (int) duk_is_array(ctx, i)); printf(" fun=%d", (int) duk_is_function(ctx, i)); printf(" cfun=%d", (int) duk_is_c_function(ctx, i)); printf(" efun=%d", (int) duk_is_ecmascript_function(ctx, i)); printf(" bfun=%d", (int) duk_is_bound_function(ctx, i)); printf(" call=%d", (int) duk_is_callable(ctx, i)); printf(" thr=%d", (int) duk_is_thread(ctx, i)); printf(" buf=%d", (int) duk_is_buffer(ctx, i)); printf(" dyn=%d", (int) duk_is_dynamic_buffer(ctx, i)); printf(" fix=%d", (int) duk_is_fixed_buffer(ctx, i)); printf(" ptr=%d", (int) duk_is_pointer(ctx, i)); printf(" prim=%d", (int) duk_is_primitive(ctx, i)); printf(" objcoerc=%d", (int) duk_is_object_coercible(ctx, i)); printf("\n"); } }
static duk_ret_t test_func(duk_context *ctx, void *udata) { (void) udata; if (ctx) { printf("dummy - return here\n"); fflush(stdout); return 0; } /* Up-to-date for Duktape 1.3.0, alphabetical order: * $ cd website/api; ls *.yaml */ (void) duk_alloc_raw(ctx, 0); (void) duk_alloc(ctx, 0); (void) duk_base64_decode(ctx, 0); (void) duk_base64_encode(ctx, 0); (void) duk_buffer_to_string(ctx, 0); (void) duk_call_method(ctx, 0); (void) duk_call_prop(ctx, 0, 0); (void) duk_call(ctx, 0); (void) duk_char_code_at(ctx, 0, 0); (void) duk_check_stack_top(ctx, 0); (void) duk_check_stack(ctx, 0); (void) duk_check_type_mask(ctx, 0, 0); (void) duk_check_type(ctx, 0, 0); (void) duk_compact(ctx, 0); (void) duk_compile_lstring_filename(ctx, 0, "dummy", 0); (void) duk_compile_lstring(ctx, 0, "dummy", 0); (void) duk_compile_string_filename(ctx, 0, "dummy"); (void) duk_compile_string(ctx, 0, "dummy"); (void) duk_compile(ctx, 0); (void) duk_concat(ctx, 0); (void) duk_config_buffer(ctx, 0, NULL, 0); (void) duk_copy(ctx, 0, 0); (void) duk_create_heap_default(); (void) duk_create_heap(NULL, NULL, NULL, NULL, NULL); (void) duk_debugger_attach(ctx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); (void) duk_debugger_cooperate(ctx); (void) duk_debugger_detach(ctx); (void) duk_debugger_notify(ctx, 0); (void) duk_debugger_pause(ctx); (void) duk_decode_string(ctx, 0, NULL, NULL); (void) duk_def_prop(ctx, 0, 0); (void) duk_del_prop_index(ctx, 0, 0); (void) duk_del_prop_string(ctx, 0, "dummy"); (void) duk_del_prop(ctx, 0); (void) duk_destroy_heap(ctx); (void) duk_dump_function(ctx); (void) duk_dup_top(ctx); (void) duk_dup(ctx, 0); (void) duk_enum(ctx, 0, 0); (void) duk_equals(ctx, 0, 0); duk_error_va(ctx, 0, NULL, NULL); duk_error(ctx, 0, "dummy"); /* (void) cast won't work without variadic macros */ (void) duk_eval_lstring_noresult(ctx, "dummy", 0); (void) duk_eval_lstring(ctx, "dummy", 0); (void) duk_eval_noresult(ctx); (void) duk_eval_string_noresult(ctx, "dummy"); (void) duk_eval_string(ctx, "dummy"); (void) duk_eval(ctx); (void) duk_fatal(ctx, "dummy"); (void) duk_free_raw(ctx, NULL); (void) duk_free(ctx, NULL); (void) duk_gc(ctx, 0); (void) duk_get_boolean(ctx, 0); (void) duk_get_buffer_data(ctx, 0, NULL); (void) duk_get_buffer(ctx, 0, NULL); (void) duk_get_c_function(ctx, 0); (void) duk_get_context(ctx, 0); (void) duk_get_current_magic(ctx); (void) duk_get_error_code(ctx, 0); (void) duk_get_finalizer(ctx, 0); (void) duk_get_global_string(ctx, 0); (void) duk_get_heapptr(ctx, 0); (void) duk_get_int(ctx, 0); (void) duk_get_length(ctx, 0); (void) duk_get_lstring(ctx, 0, NULL); (void) duk_get_magic(ctx, 0); (void) duk_get_memory_functions(ctx, NULL); (void) duk_get_number(ctx, 0); (void) duk_get_pointer(ctx, 0); (void) duk_get_prop_index(ctx, 0, 0); (void) duk_get_prop_string(ctx, 0, "dummy"); (void) duk_get_prop(ctx, 0); (void) duk_get_prototype(ctx, 0); (void) duk_get_string(ctx, 0); (void) duk_get_top_index(ctx); (void) duk_get_top(ctx); (void) duk_get_type_mask(ctx, 0); (void) duk_get_type(ctx, 0); (void) duk_get_uint(ctx, 0); (void) duk_has_prop_index(ctx, 0, 0); (void) duk_has_prop_string(ctx, 0, "dummy"); (void) duk_has_prop(ctx, 0); (void) duk_hex_decode(ctx, 0); (void) duk_hex_encode(ctx, 0); (void) duk_insert(ctx, 0); (void) duk_instanceof(ctx, 0, 0); (void) duk_is_array(ctx, 0); (void) duk_is_boolean(ctx, 0); (void) duk_is_bound_function(ctx, 0); (void) duk_is_buffer(ctx, 0); (void) duk_is_callable(ctx, 0); (void) duk_is_c_function(ctx, 0); (void) duk_is_constructor_call(ctx); (void) duk_is_dynamic_buffer(ctx, 0); (void) duk_is_ecmascript_function(ctx, 0); (void) duk_is_error(ctx, 0); (void) duk_is_eval_error(ctx, 0); (void) duk_is_fixed_buffer(ctx, 0); (void) duk_is_function(ctx, 0); (void) duk_is_lightfunc(ctx, 0); (void) duk_is_nan(ctx, 0); (void) duk_is_null_or_undefined(ctx, 0); (void) duk_is_null(ctx, 0); (void) duk_is_number(ctx, 0); (void) duk_is_object_coercible(ctx, 0); (void) duk_is_object(ctx, 0); (void) duk_is_pointer(ctx, 0); (void) duk_is_primitive(ctx, 0); (void) duk_is_range_error(ctx, 0); (void) duk_is_reference_error(ctx, 0); (void) duk_is_strict_call(ctx); (void) duk_is_string(ctx, 0); (void) duk_is_syntax_error(ctx, 0); (void) duk_is_thread(ctx, 0); (void) duk_is_type_error(ctx, 0); (void) duk_is_undefined(ctx, 0); (void) duk_is_uri_error(ctx, 0); (void) duk_is_valid_index(ctx, 0); (void) duk_join(ctx, 0); (void) duk_json_decode(ctx, 0); (void) duk_json_encode(ctx, 0); (void) duk_load_function(ctx); (void) duk_map_string(ctx, 0, NULL, NULL); (void) duk_new(ctx, 0); (void) duk_next(ctx, 0, 0); (void) duk_normalize_index(ctx, 0); (void) duk_pcall_method(ctx, 0); (void) duk_pcall_prop(ctx, 0, 0); (void) duk_pcall(ctx, 0); (void) duk_pcompile_lstring_filename(ctx, 0, "dummy", 0); (void) duk_pcompile_lstring(ctx, 0, "dummy", 0); (void) duk_pcompile_string_filename(ctx, 0, "dummy"); (void) duk_pcompile_string(ctx, 0, "dummy"); (void) duk_pcompile(ctx, 0); (void) duk_peval_lstring_noresult(ctx, "dummy", 0); (void) duk_peval_lstring(ctx, "dummy", 0); (void) duk_peval_noresult(ctx); (void) duk_peval_string_noresult(ctx, "dummy"); (void) duk_peval_string(ctx, "dummy"); (void) duk_peval(ctx); (void) duk_pnew(ctx, 0); (void) duk_pop_2(ctx); (void) duk_pop_3(ctx); (void) duk_pop_n(ctx, 0); (void) duk_pop(ctx); (void) duk_push_array(ctx); (void) duk_push_boolean(ctx, 0); (void) duk_push_buffer_object(ctx, 0, 0, 0, 0); (void) duk_push_buffer(ctx, 0, 0); (void) duk_push_c_function(ctx, NULL, 0); (void) duk_push_c_lightfunc(ctx, NULL, 0, 0, 0); (void) duk_push_context_dump(ctx); (void) duk_push_current_function(ctx); (void) duk_push_current_thread(ctx); (void) duk_push_dynamic_buffer(ctx, 0); (void) duk_push_error_object_va(ctx, 0, NULL, NULL); (void) duk_push_error_object(ctx, 0, "dummy"); (void) duk_push_external_buffer(ctx); (void) duk_push_false(ctx); (void) duk_push_fixed_buffer(ctx, 0); (void) duk_push_global_object(ctx); (void) duk_push_global_stash(ctx); (void) duk_push_heap_stash(ctx); (void) duk_push_heapptr(ctx, NULL); (void) duk_push_int(ctx, 0); (void) duk_push_lstring(ctx, "dummy", 0); (void) duk_push_nan(ctx); (void) duk_push_null(ctx); (void) duk_push_number(ctx, 0.0); (void) duk_push_object(ctx); (void) duk_push_pointer(ctx, NULL); (void) duk_push_sprintf(ctx, "dummy"); (void) duk_push_string(ctx, "dummy"); (void) duk_push_this(ctx); (void) duk_push_thread_new_globalenv(ctx); (void) duk_push_thread_stash(ctx, NULL); (void) duk_push_thread(ctx); (void) duk_push_true(ctx); (void) duk_push_uint(ctx, 0); (void) duk_push_undefined(ctx); (void) duk_push_vsprintf(ctx, "dummy", NULL); (void) duk_put_function_list(ctx, 0, NULL); (void) duk_put_global_string(ctx, NULL); (void) duk_put_number_list(ctx, 0, NULL); (void) duk_put_prop_index(ctx, 0, 0); (void) duk_put_prop_string(ctx, 0, "dummy"); (void) duk_put_prop(ctx, 0); (void) duk_realloc_raw(ctx, NULL, 0); (void) duk_realloc(ctx, NULL, 0); (void) duk_remove(ctx, 0); (void) duk_replace(ctx, 0); (void) duk_require_boolean(ctx, 0); (void) duk_require_buffer_data(ctx, 0, NULL); (void) duk_require_buffer(ctx, 0, NULL); (void) duk_require_c_function(ctx, 0); (void) duk_require_callable(ctx, 0); (void) duk_require_context(ctx, 0); (void) duk_require_function(ctx, 0); (void) duk_require_heapptr(ctx, 0); (void) duk_require_int(ctx, 0); (void) duk_require_lstring(ctx, 0, NULL); (void) duk_require_normalize_index(ctx, 0); (void) duk_require_null(ctx, 0); (void) duk_require_number(ctx, 0); (void) duk_require_object_coercible(ctx, 0); (void) duk_require_pointer(ctx, 0); (void) duk_require_stack_top(ctx, 0); (void) duk_require_stack(ctx, 0); (void) duk_require_string(ctx, 0); (void) duk_require_top_index(ctx); (void) duk_require_type_mask(ctx, 0, 0); (void) duk_require_uint(ctx, 0); (void) duk_require_undefined(ctx, 0); (void) duk_require_valid_index(ctx, 0); (void) duk_resize_buffer(ctx, 0, 0); (void) duk_safe_call(ctx, NULL, NULL, 0, 0); (void) duk_safe_to_lstring(ctx, 0, NULL); (void) duk_safe_to_string(ctx, 0); (void) duk_set_finalizer(ctx, 0); (void) duk_set_global_object(ctx); (void) duk_set_magic(ctx, 0, 0); (void) duk_set_prototype(ctx, 0); (void) duk_set_top(ctx, 0); (void) duk_steal_buffer(ctx, 0, NULL); (void) duk_strict_equals(ctx, 0, 0); (void) duk_substring(ctx, 0, 0, 0); (void) duk_swap_top(ctx, 0); (void) duk_swap(ctx, 0, 0); (void) duk_throw(ctx); (void) duk_to_boolean(ctx, 0); (void) duk_to_buffer(ctx, 0, NULL); (void) duk_to_defaultvalue(ctx, 0, 0); (void) duk_to_dynamic_buffer(ctx, 0, NULL); (void) duk_to_fixed_buffer(ctx, 0, NULL); (void) duk_to_int32(ctx, 0); (void) duk_to_int(ctx, 0); (void) duk_to_lstring(ctx, 0, NULL); (void) duk_to_null(ctx, 0); (void) duk_to_number(ctx, 0); (void) duk_to_object(ctx, 0); (void) duk_to_pointer(ctx, 0); (void) duk_to_primitive(ctx, 0, 0); (void) duk_to_string(ctx, 0); (void) duk_to_uint16(ctx, 0); (void) duk_to_uint32(ctx, 0); (void) duk_to_uint(ctx, 0); (void) duk_to_undefined(ctx, 0); (void) duk_trim(ctx, 0); (void) duk_xcopy_top(ctx, NULL, 0); (void) duk_xmove_top(ctx, NULL, 0); printf("never here\n"); fflush(stdout); return 0; }
static duk_ret_t test_1(duk_context *ctx) { duk_int_t i, j, n; char *ptr; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 1); duk_push_number(ctx, -123.456); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_number(ctx, -INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_lstring(ctx, "foo\0bar", 7); duk_push_object(ctx); duk_push_thread(ctx); (void) duk_push_fixed_buffer(ctx, 0); ptr = (char *) duk_push_fixed_buffer(ctx, 16); for (i = 0; i < 16; i++) { ptr[i] = (char) ('a' + i); } (void) duk_push_dynamic_buffer(ctx, 0); ptr = (char *) duk_push_dynamic_buffer(ctx, 16); for (i = 0; i < 16; i++) { ptr[i] = (char) ('a' + i); } duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeef); n = duk_get_top(ctx); printf("top: %ld\n", (long) n); for (i = 0; i < n; i++) { const unsigned char *p; duk_size_t sz; duk_dup(ctx, i); sz = (duk_size_t) 0xdeadbeef; p = (const unsigned char *) duk_to_lstring(ctx, -1, &sz); printf("index %ld, string: '", (long) i); for (j = 0; j < sz; j++) { if (p[j] >= 0x20 && p[j] <= 0x7e) { printf("%c", (int) p[j]); } else { printf("\\x%02x", (int) p[j]); } } printf("', length %lu\n", (unsigned long) sz); duk_pop(ctx); duk_dup(ctx, i); sz = (duk_size_t) 0xdeadbeef; p = (const unsigned char *) duk_to_lstring(ctx, -1, NULL); printf("index %ld, string: '%s'\n", (long) i, (const char *) p); duk_pop(ctx); } return 0; }
//duk_idx_t duk_push_thread(duk_context *ctx); duk_idx_t aperl_duk_push_thread(duk_context *ctx) { duk_idx_t ret = duk_push_thread(ctx); return ret; }
static duk_ret_t test_1(duk_context *ctx) { duk_idx_t i, n; duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_push_null(ctx); duk_push_true(ctx); duk_push_false(ctx); duk_push_int(ctx, 0); duk_push_int(ctx, 1); duk_push_int(ctx, -1); duk_push_number(ctx, 123.456); duk_push_number(ctx, -123.456); duk_push_number(ctx, 123.999); duk_push_number(ctx, -123.999); duk_push_number(ctx, -2147483649.0); /* min int32 - 1 */ duk_push_number(ctx, -2147483648.0); /* min int32 */ duk_push_number(ctx, 2147483647.0); /* max int32 */ duk_push_number(ctx, 2147483648.0); /* max int32 + 1 */ duk_push_number(ctx, 4294967295.0); /* max uint32 */ duk_push_number(ctx, 4294967296.0); /* max uint32 + 1 */ duk_push_number(ctx, 65535.0); /* max uint16 */ duk_push_number(ctx, 65536.0); /* max uint16 + 1 */ duk_push_number(ctx, 9999999999.0); duk_push_nan(ctx); duk_push_number(ctx, INFINITY); duk_push_string(ctx, ""); duk_push_string(ctx, "foo"); duk_push_string(ctx, "123"); duk_push_string(ctx, "123.456"); duk_push_string(ctx, "123.456e3"); duk_push_string(ctx, " -123.456e+3 "); duk_push_string(ctx, "NaN"); duk_push_string(ctx, "-Infinity"); duk_push_string(ctx, "+Infinity"); duk_push_string(ctx, "Infinity"); duk_push_string(ctx, "Infinityx"); duk_push_string(ctx, "xInfinity"); duk_push_string(ctx, " Infinity "); duk_push_object(ctx); duk_push_thread(ctx); duk_push_fixed_buffer(ctx, 0); /* ToNumber('') = 0 */ duk_push_fixed_buffer(ctx, 1024); /* ToNumber('\u0000...') = NaN, converts into 0 when doing integer coercion */ duk_push_dynamic_buffer(ctx, 0); duk_push_dynamic_buffer(ctx, 1024); duk_push_pointer(ctx, (void *) NULL); duk_push_pointer(ctx, (void *) 0xdeadbeef); n = duk_get_top(ctx); printf("top: %ld\n", (long) n); for (i = 0; i < n; i++) { duk_double_t dval_pre; duk_double_t dval_post; duk_int_t ival; duk_uint_t uval; duk_dup(ctx, i); dval_pre = duk_get_number(ctx, -1); ival = duk_to_int32(ctx, -1); dval_post = duk_get_number(ctx, -1); printf("index %ld, int32: %ld, number before: %lf, number after: %lf\n", (long) i, (long) ival, (double) dval_pre, (double) dval_post); duk_pop(ctx); duk_dup(ctx, i); dval_pre = duk_get_number(ctx, -1); uval = duk_to_uint32(ctx, -1); dval_post = duk_get_number(ctx, -1); printf("index %ld, uint32: %lu, number before: %lf, number after: %lf\n", (long) i, (unsigned long) uval, (double) dval_pre, (double) dval_post); duk_pop(ctx); duk_dup(ctx, i); dval_pre = duk_get_number(ctx, -1); uval = duk_to_uint16(ctx, -1); dval_post = duk_get_number(ctx, -1); printf("index %ld, uint16: %lu, number before: %lf, number after: %lf\n", (long) i, (unsigned long) uval, (double) dval_pre, (double) dval_post); duk_pop(ctx); } return 0; }