static duk_ret_t test_1(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_pointer(ctx, (void *) 0xdeadbeef); duk_push_pointer(ctx, (void *) NULL); printf("pointer: %p\n", duk_require_pointer(ctx, 0)); printf("pointer: %p\n", duk_require_pointer(ctx, 1)); return 0; }
gpointer _gum_duk_steal_data (duk_context * ctx, duk_idx_t index) { gpointer result = NULL; duk_dup (ctx, index); duk_get_prop_string (ctx, -1, "\xff" "priv"); if (!duk_is_undefined (ctx, -1)) { result = duk_require_pointer (ctx, -1); duk_pop (ctx); duk_push_pointer (ctx, NULL); duk_put_prop_string (ctx, -2, "\xff" "priv"); duk_pop (ctx); } else { duk_pop_2 (ctx); } return result; }
int js_getint(duk_context* c) { int* ptr = (int*)duk_require_pointer(c, -1); int off = duk_require_int(c,-2); ptr+=off; duk_push_int(c,*ptr); return 1; }
/* * Set buffering type for file object. Args: * - 0: FILE * - 1: mode (0 is unbuffered, 1 is line buffered) */ static duk_ret_t io_setvbuf(duk_context* ctx) { FILE* f; int mode; size_t size; f = duk_require_pointer(ctx, 0); mode = duk_require_int(ctx, 1); if (mode == 0) { mode = _IONBF; size = 0; } else if (mode == 1) { mode = _IOLBF; size = BUFSIZ; } else { abort(); } /* * Ignore erros. According to the man page: "It may set errno on failure.". Sigh. */ (void) setvbuf(f, NULL, mode, size); duk_push_undefined(ctx); return 1; }
static int sjs__compile_execute(duk_context *ctx) { const char *code; const char* filename; duk_size_t len; bool use_strict; int flags; /* [ ... use_strict code len filename ] */ use_strict = duk_require_boolean(ctx, -4); code = duk_require_pointer(ctx, -3); len = duk_require_uint(ctx, -2); filename = duk_require_string(ctx, -1); flags = 0; if (use_strict) { flags |= DUK_COMPILE_STRICT; } /* remove shebang if present */ if (strncmp(code, "#!", 2) == 0) { memcpy((void*) code, "//", 2); } duk_compile_lstring_filename(ctx, flags, code, len); /* [ ... use_strict code len function ] */ duk_push_global_object(ctx); /* 'this' binding */ duk_push_string(ctx, filename); duk_put_prop_string(ctx, -2, "__file__"); duk_call_method(ctx, 0); return 1; /* either the result or error are on the stack top */ }
int js_setint(duk_context* c) { int* ptr = (int*)duk_require_pointer(c, -1); int off = duk_require_int(c, -2); int value = duk_require_int(c, -3); ptr+=off; *ptr = value; return 0; }
static int NativeI2cFinalizer(duk_context* ctx) { AJ_InfoPrintf(("Closing i2c\n")); duk_get_prop_string(ctx, 0, AJS_HIDDEN_PROP("ctx")); AJS_TargetIO_I2cClose(duk_require_pointer(ctx, -1)); duk_pop(ctx); return 0; }
/* * Close the file. Args: * - 0: FILE */ static duk_ret_t io_fclose(duk_context* ctx) { FILE* f; f = duk_require_pointer(ctx, 0); fclose(f); duk_push_undefined(ctx); return 1; }
/* * Get pin context pointer from the "this" object */ void* PinCtxPtr(duk_context* ctx) { void* pinCtx; duk_push_this(ctx); duk_get_prop_string(ctx, -1, AJS_HIDDEN_PROP("ctx")); pinCtx = duk_require_pointer(ctx, -1); duk_pop_2(ctx); return pinCtx; }
/* * Get the fd associated with a file. Args: * - 0: FILE */ static duk_ret_t io_fileno(duk_context* ctx) { FILE* f; int fd; f = duk_require_pointer(ctx, 0); fd = fileno(f); duk_push_int(ctx, fd); return 1; }
gboolean _gum_duk_get_pointer (duk_context * ctx, duk_idx_t index, GumDukCore * core, gpointer * ptr) { gboolean success = TRUE; duk_dup (ctx, index); duk_push_heapptr (ctx, core->native_pointer); if (duk_is_pointer (ctx, -2)) { *ptr = duk_require_pointer (ctx, -2); } else if (duk_instanceof (ctx, -2, -1)) { GumDukNativePointer * p; p = _gum_duk_require_data (ctx, -2); *ptr = p->value; } else if (duk_is_object (ctx, -2)) { gboolean is_native_pointer; duk_get_prop_string (ctx, -2, "handle"); is_native_pointer = duk_instanceof (ctx, -1, -2); if (is_native_pointer) { GumDukNativePointer * p; p = _gum_duk_require_data (ctx, -1); *ptr = p->value; } else { success = FALSE; } duk_pop (ctx); } else { success = FALSE; } duk_pop_2 (ctx); return success; }
gpointer _gum_duk_require_data (duk_context * ctx, duk_idx_t index) { gpointer result; duk_get_prop_string (ctx, index, "\xff" "priv"); result = duk_require_pointer (ctx, -1); duk_pop (ctx); return result; }
gpointer _gum_duk_get_data (duk_context * ctx, duk_idx_t index) { gpointer result; duk_get_prop_string (ctx, index, "\xff" "priv"); if (!duk_is_undefined (ctx, -1)) result = duk_require_pointer (ctx, -1); else result = NULL; duk_pop (ctx); return result; }
/* * Flush the file write buffer. Args: * - 0: FILE */ static duk_ret_t io_fflush(duk_context* ctx) { FILE* f; int r; f = duk_require_pointer(ctx, 0); r = fflush(f); if (r != 0) { SJS_THROW_ERRNO_ERROR(); return -42; /* control never returns here */ } duk_push_undefined(ctx); return 1; }
static duk_ret_t pmain (duk_context *ctx) { int argc; const char** argv; argc = duk_require_int(ctx, 0); argv = duk_require_pointer(ctx, 1); prepare_duk_env(ctx); duknode_push_argv(ctx, argc, argv); if (duk_peval_file(ctx, "node-main.js") != 0) { duk_error(ctx, DUK_ERR_INTERNAL_ERROR, "%s\n", duk_safe_to_string(ctx, -1)); return -1; } duk_pop(ctx); /* ignore result */ return 0; }
static int sjs__compile_execute(duk_context *ctx) { const char *code; duk_size_t len; /* [ ... code len filename ] */ code = duk_require_pointer(ctx, -3); len = duk_require_uint(ctx, -2); duk_compile_lstring_filename(ctx, DUK_COMPILE_STRICT, code, len); /* [ ... code len function ] */ duk_push_global_object(ctx); /* 'this' binding */ duk_call_method(ctx, 0); return 1; /* either the result or error are on the stack top */ }
gboolean _gum_duk_get_uint64 (duk_context * ctx, duk_idx_t index, GumDukCore * core, guint64 * u) { if (duk_is_pointer (ctx, index)) { *u = *((const guint64 *) duk_require_pointer (ctx, index)); return TRUE; } else if (duk_is_number (ctx, index)) { duk_double_t number; number = duk_require_number (ctx, index); if (number < 0) return FALSE; *u = (guint64) number; return TRUE; } else { gboolean success = FALSE; duk_dup (ctx, index); duk_push_heapptr (ctx, core->uint64); if (duk_instanceof (ctx, -2, -1)) { GumDukUInt64 * object; object = _gum_duk_require_data (ctx, -2); *u = object->value; success = TRUE; } duk_pop_2 (ctx); return success; } }
/* * Write data to a file. Args: * - 0: FILE * - 1: data */ static duk_ret_t io_fwrite(duk_context* ctx) { FILE* f; size_t len, r; const char* buf; f = duk_require_pointer(ctx, 0); if (duk_is_string(ctx, 1)) { buf = duk_require_lstring(ctx, 1, &len); } else { buf = duk_require_buffer_data(ctx, 1, &len); } r = fwrite(buf, 1, len, f); if (ferror(f) || feof(f)) { clearerr(f); SJS_THROW_ERRNO_ERROR2(EIO); return -42; /* control never returns here */ } else { duk_push_int(ctx, r); return 1; } }
/* * Read a line from a file. Args: * - 0: FILE * - 1: nread (a number or a Buffer-ish object) */ static duk_ret_t io_fgets(duk_context* ctx) { FILE* f; size_t nread; char* r; char* buf; char* alloc_buf = NULL; f = duk_require_pointer(ctx, 0); if (duk_is_number(ctx, 1)) { nread = duk_require_int(ctx, 1); alloc_buf = malloc(nread); if (!alloc_buf) { SJS_THROW_ERRNO_ERROR2(ENOMEM); return -42; /* control never returns here */ } buf = alloc_buf; } else { buf = duk_require_buffer_data(ctx, 1, &nread); if (buf == NULL || nread == 0) { duk_error(ctx, DUK_ERR_TYPE_ERROR, "invalid buffer"); return -42; /* control never returns here */ } } r = fgets(buf, nread, f); if (r == NULL) { duk_push_string(ctx, ""); } else { if (alloc_buf) { /* return the string we read */ duk_push_string(ctx, r); } else { /* the data was written to the buffer, return how much we read */ duk_push_int(ctx, strlen(r)); } } free(alloc_buf); return 1; }
/* * Read data from a file. Args: * - 0: FILE * - 1: nread (a number or a Buffer-ish object) */ static duk_ret_t io_fread(duk_context* ctx) { FILE* f; size_t nread, r; char* buf; int create_buf = 0; f = duk_require_pointer(ctx, 0); if (duk_is_number(ctx, 1)) { nread = duk_require_int(ctx, 1); buf = duk_push_dynamic_buffer(ctx, nread); create_buf = 1; } else { buf = duk_require_buffer_data(ctx, 1, &nread); if (buf == NULL || nread == 0) { duk_error(ctx, DUK_ERR_TYPE_ERROR, "invalid buffer"); return -42; /* control never returns here */ } } r = fread(buf, 1, nread, f); if (ferror(f)) { if (create_buf) { duk_pop(ctx); } clearerr(f); SJS_THROW_ERRNO_ERROR2(EIO); return -42; /* control never returns here */ } if (create_buf) { /* return the string we read */ duk_resize_buffer(ctx, -1, r); } else { /* the data was written to the buffer, return how much we read */ duk_push_int(ctx, r); } return 1; }
gboolean _gum_duk_get_int64 (duk_context * ctx, duk_idx_t index, GumDukCore * core, gint64 * i) { if (duk_is_pointer (ctx, index)) { *i = *((const gint64 *) duk_require_pointer (ctx, index)); return TRUE; } else if (duk_is_number (ctx, index)) { *i = (gint64) duk_require_number (ctx, index); return TRUE; } else { gboolean success = FALSE; duk_dup (ctx, index); duk_push_heapptr (ctx, core->int64); if (duk_instanceof (ctx, -2, -1)) { GumDukInt64 * object; object = _gum_duk_require_data (ctx, -2); *i = object->value; success = TRUE; } duk_pop_2 (ctx); return success; } }
static int wrapped_compile_execute(duk_context *ctx) { const char *src_data; duk_size_t src_len; int comp_flags; /* XXX: Here it'd be nice to get some stats for the compilation result * when a suitable command line is given (e.g. code size, constant * count, function count. These are available internally but not through * the public API. */ /* Use duk_compile_lstring_filename() variant which avoids interning * the source code. This only really matters for low memory environments. */ /* [ ... bytecode_filename src_data src_len filename ] */ src_data = (const char *) duk_require_pointer(ctx, -3); src_len = (duk_size_t) duk_require_uint(ctx, -2); if (src_data != NULL && src_len >= 2 && src_data[0] == (char) 0xff) { /* Bytecode. */ duk_push_lstring(ctx, src_data, src_len); duk_to_buffer(ctx, -1, NULL); duk_load_function(ctx); } else { /* Source code. */ comp_flags = 0; duk_compile_lstring_filename(ctx, comp_flags, src_data, src_len); } /* [ ... bytecode_filename src_data src_len function ] */ /* Optional bytecode dump. */ if (duk_is_string(ctx, -4)) { FILE *f; void *bc_ptr; duk_size_t bc_len; size_t wrote; duk_dup_top(ctx); duk_dump_function(ctx); bc_ptr = duk_require_buffer(ctx, -1, &bc_len); f = fopen(duk_require_string(ctx, -5), "wb"); if (!f) { duk_error(ctx, DUK_ERR_ERROR, "failed to open bytecode output file"); } wrote = fwrite(bc_ptr, 1, (size_t) bc_len, f); /* XXX: handle partial writes */ (void) fclose(f); if (wrote != bc_len) { duk_error(ctx, DUK_ERR_ERROR, "failed to write all bytecode"); } return 0; /* duk_safe_call() cleans up */ } #if 0 /* Manual test for bytecode dump/load cycle: dump and load before * execution. Enable manually, then run "make qecmatest" for a * reasonably good coverage of different functions and programs. */ duk_dump_function(ctx); duk_load_function(ctx); #endif #if defined(DUK_CMDLINE_AJSHEAP) ajsheap_start_exec_timeout(); #endif duk_push_global_object(ctx); /* 'this' binding */ duk_call_method(ctx, 0); #if defined(DUK_CMDLINE_AJSHEAP) ajsheap_clear_exec_timeout(); #endif if (interactive_mode) { /* * In interactive mode, write to stdout so output won't * interleave as easily. * * NOTE: the ToString() coercion may fail in some cases; * for instance, if you evaluate: * * ( {valueOf: function() {return {}}, * toString: function() {return {}}}); * * The error is: * * TypeError: failed to coerce with [[DefaultValue]] * duk_api.c:1420 * * These are handled now by the caller which also has stack * trace printing support. User code can print out errors * safely using duk_safe_to_string(). */ fprintf(stdout, "= %s\n", duk_to_string(ctx, -1)); fflush(stdout); } else { /* In non-interactive mode, success results are not written at all. * It is important that the result value is not string coerced, * as the string coercion may cause an error in some cases. */ } return 0; /* duk_safe_call() cleans up */ }
static duk_ret_t test_3(duk_context *ctx) { duk_set_top(ctx, 0); printf("pointer: %p\n", duk_require_pointer(ctx, 0)); return 0; }
static duk_ret_t test_4(duk_context *ctx) { duk_set_top(ctx, 0); printf("pointer: %p\n", duk_require_pointer(ctx, DUK_INVALID_INDEX)); return 0; }
int js_getbyte(duk_context* c) { byte* off = (byte*)duk_require_pointer(c, -1); duk_push_int(c, *off); return 1; }
/* Helper which can be called both directly and with duk_safe_call(). */ DUK_LOCAL duk_ret_t duk__do_compile(duk_context *ctx) { duk_hthread *thr = (duk_hthread *) ctx; duk__compile_raw_args *comp_args; duk_uint_t flags; duk_small_uint_t comp_flags; duk_hcompiledfunction *h_templ; /* Note: strictness is not inherited from the current Duktape/C * context. Otherwise it would not be possible to compile * non-strict code inside a Duktape/C activation (which is * always strict now). See api-testcases/test-eval-strictness.c * for discussion. */ /* [ ... source? filename &comp_args ] (depends on flags) */ comp_args = (duk__compile_raw_args *) duk_require_pointer(ctx, -1); flags = comp_args->flags; duk_pop(ctx); /* [ ... source? filename ] */ if (!comp_args->src_buffer) { duk_hstring *h_sourcecode; h_sourcecode = duk_get_hstring(ctx, -2); if ((flags & DUK_COMPILE_NOSOURCE) || /* args incorrect */ (h_sourcecode == NULL)) { /* e.g. duk_push_file_string_raw() pushed undefined */ /* XXX: when this error is caused by a nonexistent * file given to duk_peval_file() or similar, the * error message is not the best possible. */ DUK_ERROR(thr, DUK_ERR_API_ERROR, DUK_STR_NO_SOURCECODE); } DUK_ASSERT(h_sourcecode != NULL); comp_args->src_buffer = (const duk_uint8_t *) DUK_HSTRING_GET_DATA(h_sourcecode); comp_args->src_length = (duk_size_t) DUK_HSTRING_GET_BYTELEN(h_sourcecode); } DUK_ASSERT(comp_args->src_buffer != NULL); /* XXX: unnecessary translation of flags */ comp_flags = 0; if (flags & DUK_COMPILE_EVAL) { comp_flags |= DUK_JS_COMPILE_FLAG_EVAL; } if (flags & DUK_COMPILE_FUNCTION) { comp_flags |= DUK_JS_COMPILE_FLAG_EVAL | DUK_JS_COMPILE_FLAG_FUNCEXPR; } if (flags & DUK_COMPILE_STRICT) { comp_flags |= DUK_JS_COMPILE_FLAG_STRICT; } /* [ ... source? filename ] */ duk_js_compile(thr, comp_args->src_buffer, comp_args->src_length, comp_flags); /* [ ... source? func_template ] */ if (flags & DUK_COMPILE_NOSOURCE) { ; } else { duk_remove(ctx, -2); } /* [ ... func_template ] */ h_templ = (duk_hcompiledfunction *) duk_get_hobject(ctx, -1); DUK_ASSERT(h_templ != NULL); duk_js_push_closure(thr, h_templ, thr->builtins[DUK_BIDX_GLOBAL_ENV], thr->builtins[DUK_BIDX_GLOBAL_ENV]); duk_remove(ctx, -2); /* -> [ ... closure ] */ /* [ ... closure ] */ return 1; }
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 int wrapped_compile_execute(duk_context *ctx) { const char *src_data; duk_size_t src_len; int comp_flags; /* XXX: Here it'd be nice to get some stats for the compilation result * when a suitable command line is given (e.g. code size, constant * count, function count. These are available internally but not through * the public API. */ /* Use duk_compile_lstring_filename() variant which avoids interning * the source code. This only really matters for low memory environments. */ /* [ ... src_data src_len filename ] */ comp_flags = 0; src_data = (const char *) duk_require_pointer(ctx, -3); src_len = (duk_size_t) duk_require_uint(ctx, -2); duk_compile_lstring_filename(ctx, comp_flags, src_data, src_len); /* [ ... src_data src_len function ] */ #if defined(DUK_CMDLINE_AJSHEAP) ajsheap_start_exec_timeout(); #endif duk_push_global_object(ctx); /* 'this' binding */ duk_call_method(ctx, 0); #if defined(DUK_CMDLINE_AJSHEAP) ajsheap_clear_exec_timeout(); #endif if (interactive_mode) { /* * In interactive mode, write to stdout so output won't * interleave as easily. * * NOTE: the ToString() coercion may fail in some cases; * for instance, if you evaluate: * * ( {valueOf: function() {return {}}, * toString: function() {return {}}}); * * The error is: * * TypeError: failed to coerce with [[DefaultValue]] * duk_api.c:1420 * * These are handled now by the caller which also has stack * trace printing support. User code can print out errors * safely using duk_safe_to_string(). */ fprintf(stdout, "= %s\n", duk_to_string(ctx, -1)); fflush(stdout); } else { /* In non-interactive mode, success results are not written at all. * It is important that the result value is not string coerced, * as the string coercion may cause an error in some cases. */ } duk_pop(ctx); return 0; }
//void *duk_require_pointer(duk_context *ctx, duk_idx_t index); void *aperl_duk_require_pointer(duk_context *ctx, duk_idx_t index) { void *ret = duk_require_pointer(ctx, index); return ret; }
static duk_ret_t test__pointer(duk_context *ctx, void *udata) { (void) udata; (void) duk_require_pointer(ctx, -3); return 0; }