int duk_builtin_object_constructor(duk_context *ctx) { if (!duk_is_constructor_call(ctx) && !duk_is_null_or_undefined(ctx, 0)) { duk_to_object(ctx, 0); return 1; } if (duk_is_object(ctx, 0)) { return 1; } if (duk_check_type_mask(ctx, 0, DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER)) { duk_to_object(ctx, 0); return 1; } /* FIXME: handling for POINTER and BUFFER */ duk_push_object_helper(ctx, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; }
DUK_INTERNAL duk_ret_t duk_bi_object_constructor(duk_context *ctx) { if (!duk_is_constructor_call(ctx) && !duk_is_null_or_undefined(ctx, 0)) { duk_to_object(ctx, 0); return 1; } if (duk_is_object(ctx, 0)) { return 1; } /* Pointer and buffer primitive values are treated like other * primitives values which have a fully fledged object counterpart: * promote to an object value. Lightfuncs are coerced with * ToObject() even they could also be returned as is. */ if (duk_check_type_mask(ctx, 0, DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { duk_to_object(ctx, 0); return 1; } duk_push_object_helper(ctx, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; }
DUK_INTERNAL duk_ret_t duk_bi_object_constructor_assign(duk_hthread *thr) { duk_idx_t nargs; duk_int_t idx; nargs = duk_get_top_require_min(thr, 1 /*min_top*/); duk_to_object(thr, 0); for (idx = 1; idx < nargs; idx++) { /* E7 19.1.2.1 (step 4a) */ if (duk_is_null_or_undefined(thr, idx)) { continue; } /* duk_enum() respects ES2015+ [[OwnPropertyKeys]] ordering, which is * convenient here. */ duk_to_object(thr, idx); duk_enum(thr, idx, DUK_ENUM_OWN_PROPERTIES_ONLY); while (duk_next(thr, -1, 1 /*get_value*/)) { /* [ target ... enum key value ] */ duk_put_prop(thr, 0); /* [ target ... enum ] */ } /* Could pop enumerator, but unnecessary because of duk_set_top() * below. */ } duk_set_top(thr, 1); return 1; }
static duk_ret_t test_2g(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_pointer(ctx, (void *) NULL); duk_to_object(ctx, 0); printf("index 0 OK\n"); return 0; }
int test_2e(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_dynamic_buffer(ctx, 0); duk_to_object(ctx, 0); printf("index 0 OK\n"); return 0; }
int duk_builtin_object_prototype_to_string(duk_context *ctx) { duk_hthread *thr = (duk_hthread *) ctx; duk_push_this(ctx); duk_push_string(ctx, "[object "); if (duk_is_undefined(ctx, -2)) { duk_push_string(ctx, "Undefined"); } else if (duk_is_null(ctx, -2)) { duk_push_string(ctx, "Null"); } else { duk_hobject *h_this; duk_hstring *h_classname; duk_to_object(ctx, -2); h_this = duk_get_hobject(ctx, -2); DUK_ASSERT(h_this != NULL); h_classname = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h_this); DUK_ASSERT(h_classname != NULL); duk_push_hstring(ctx, h_classname); } duk_push_string(ctx, "]"); duk_concat(ctx, 3); return 1; }
int test_2b(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_null(ctx); duk_to_object(ctx, 0); printf("index 0 OK\n"); return 0; }
DUK_INTERNAL duk_ret_t duk_bi_object_prototype_to_string(duk_context *ctx) { duk_hthread *thr = (duk_hthread *) ctx; duk_push_this(ctx); duk_push_string(ctx, "[object "); if (duk_is_undefined(ctx, -2)) { duk_push_hstring_stridx(ctx, DUK_STRIDX_UC_UNDEFINED); } else if (duk_is_null(ctx, -2)) { duk_push_hstring_stridx(ctx, DUK_STRIDX_UC_NULL); } else { duk_hobject *h_this; duk_hstring *h_classname; duk_to_object(ctx, -2); h_this = duk_get_hobject(ctx, -2); DUK_ASSERT(h_this != NULL); h_classname = DUK_HOBJECT_GET_CLASS_STRING(thr->heap, h_this); DUK_ASSERT(h_classname != NULL); duk_push_hstring(ctx, h_classname); } duk_push_string(ctx, "]"); duk_concat(ctx, 3); return 1; }
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; }
/* non-coercible types */ int test_2a(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_undefined(ctx); duk_to_object(ctx, 0); printf("index 0 OK\n"); return 0; }
int test_2d(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_fixed_buffer(ctx, 1024); duk_to_object(ctx, 0); printf("index 0 OK\n"); return 0; }
int test_2h(duk_context *ctx) { duk_set_top(ctx, 0); duk_push_pointer(ctx, (void *) 0xdeadbeef); duk_to_object(ctx, 0); printf("index 0 OK\n"); return 0; }
DUK_INTERNAL duk_ret_t duk_bi_object_prototype_lookupaccessor(duk_hthread *thr) { duk_uint_t sanity; duk_push_this(thr); duk_to_object(thr, -1); /* XXX: Prototype walk (with sanity) should be a core property * operation, could add a flag to e.g. duk_get_prop_desc(). */ /* ToPropertyKey() coercion is not needed, duk_get_prop_desc() does it. */ sanity = DUK_HOBJECT_PROTOTYPE_CHAIN_SANITY; while (!duk_is_undefined(thr, -1)) { /* [ key obj ] */ duk_dup(thr, 0); duk_get_prop_desc(thr, 1, 0 /*flags*/); if (!duk_is_undefined(thr, -1)) { duk_get_prop_stridx(thr, -1, (duk_get_current_magic(thr) != 0 ? DUK_STRIDX_SET : DUK_STRIDX_GET)); return 1; } duk_pop(thr); if (DUK_UNLIKELY(sanity-- == 0)) { DUK_ERROR_RANGE(thr, DUK_STR_PROTOTYPE_CHAIN_LIMIT); DUK_WO_NORETURN(return 0;); }
DUK_INTERNAL duk_ret_t duk_bi_object_constructor_get_own_property_descriptor(duk_hthread *thr) { DUK_ASSERT_TOP(thr, 2); /* ES2015 Section 19.1.2.6, step 1 */ if (duk_get_current_magic(thr) == 0) { duk_to_object(thr, 0); } /* [ obj key ] */ duk_hobject_object_get_own_property_descriptor(thr, -2); return 1; }
DUK_INTERNAL duk_ret_t duk_bi_object_constructor(duk_hthread *thr) { duk_uint_t arg_mask; arg_mask = duk_get_type_mask(thr, 0); if (!duk_is_constructor_call(thr) && /* not a constructor call */ ((arg_mask & (DUK_TYPE_MASK_NULL | DUK_TYPE_MASK_UNDEFINED)) == 0)) { /* and argument not null or undefined */ duk_to_object(thr, 0); return 1; } /* Pointer and buffer primitive values are treated like other * primitives values which have a fully fledged object counterpart: * promote to an object value. Lightfuncs and plain buffers are * coerced with ToObject() even they could also be returned as is. */ if (arg_mask & (DUK_TYPE_MASK_OBJECT | DUK_TYPE_MASK_STRING | DUK_TYPE_MASK_BOOLEAN | DUK_TYPE_MASK_NUMBER | DUK_TYPE_MASK_POINTER | DUK_TYPE_MASK_BUFFER | DUK_TYPE_MASK_LIGHTFUNC)) { /* For DUK_TYPE_OBJECT the coercion is a no-op and could * be checked for explicitly, but Object(obj) calls are * not very common so opt for minimal footprint. */ duk_to_object(thr, 0); return 1; } (void) duk_push_object_helper(thr, DUK_HOBJECT_FLAG_EXTENSIBLE | DUK_HOBJECT_FLAG_FASTREFS | DUK_HOBJECT_CLASS_AS_FLAGS(DUK_HOBJECT_CLASS_OBJECT), DUK_BIDX_OBJECT_PROTOTYPE); return 1; }
int test_1(duk_context *ctx) { int i, n; duk_set_top(ctx, 0); duk_push_object(ctx); duk_push_int(ctx, 123); duk_to_object(ctx, -1); /* ToObject(123) is a Number object */ duk_push_true(ctx); duk_to_object(ctx, -1); /* ToObject(true) is a Boolean object */ n = duk_get_top(ctx); printf("top: %d\n", n); for (i = 0; i < n; i++) { int t1, t2; t1 = duk_get_type(ctx, i); duk_to_defaultvalue(ctx, i, DUK_HINT_NONE); t2 = duk_get_type(ctx, i); printf("index %d, type %d -> %d, result: %s\n", i, t1, t2, duk_to_string(ctx, i)); } return 0; }
/* Shared helper to implement Object.getPrototypeOf, * Object.prototype.__proto__ getter, and Reflect.getPrototypeOf. * * http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-object.prototype.__proto__ */ DUK_INTERNAL duk_ret_t duk_bi_object_getprototype_shared(duk_context *ctx) { /* * magic = 0: __proto__ getter * magic = 1: Object.getPrototypeOf() * magic = 2: Reflect.getPrototypeOf() */ duk_hthread *thr = (duk_hthread *) ctx; duk_hobject *h; duk_hobject *proto; duk_tval *tv; duk_int_t magic; magic = duk_get_current_magic(ctx); if (magic == 0) { DUK_ASSERT_TOP(ctx, 0); duk_push_this_coercible_to_object(ctx); } DUK_ASSERT(duk_get_top(ctx) >= 1); if (magic < 2) { /* ES2015 Section 19.1.2.9, step 1 */ duk_to_object(ctx, 0); } tv = DUK_GET_TVAL_POSIDX(ctx, 0); switch (DUK_TVAL_GET_TAG(tv)) { case DUK_TAG_BUFFER: proto = thr->builtins[DUK_BIDX_UINT8ARRAY_PROTOTYPE]; break; case DUK_TAG_LIGHTFUNC: proto = thr->builtins[DUK_BIDX_FUNCTION_PROTOTYPE]; break; case DUK_TAG_OBJECT: h = DUK_TVAL_GET_OBJECT(tv); proto = DUK_HOBJECT_GET_PROTOTYPE(thr->heap, h); break; default: /* This implicitly handles CheckObjectCoercible() caused * TypeError. */ DUK_DCERROR_TYPE_INVALID_ARGS(thr); } if (proto != NULL) { duk_push_hobject(ctx, proto); } else { duk_push_null(ctx); } return 1; }
DUK_INTERNAL duk_ret_t duk_bi_object_prototype_defineaccessor(duk_hthread *thr) { duk_push_this(thr); duk_insert(thr, 0); duk_to_object(thr, 0); duk_require_callable(thr, 2); /* [ ToObject(this) key getter/setter ] */ /* ToPropertyKey() coercion is not needed, duk_def_prop() does it. */ duk_def_prop(thr, 0, DUK_DEFPROP_SET_ENUMERABLE | DUK_DEFPROP_SET_CONFIGURABLE | (duk_get_current_magic(thr) ? DUK_DEFPROP_HAVE_SETTER : DUK_DEFPROP_HAVE_GETTER)); 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; }
int duk_builtin_date_prototype_to_json(duk_context *ctx) { /* Note: toJSON() is a generic function which works even if 'this' * is not a Date. The sole argument is ignored. */ duk_push_this(ctx); duk_to_object(ctx, -1); duk_dup_top(ctx); duk_to_primitive(ctx, -1, DUK_HINT_NUMBER); if (duk_is_number(ctx, -1)) { double d = duk_get_number(ctx, -1); if (!DUK_ISFINITE(d)) { duk_push_null(ctx); return 1; } } duk_pop(ctx); duk_get_prop_stridx(ctx, -1, DUK_STRIDX_TO_ISO_STRING); duk_dup(ctx, -2); /* -> [ O toIsoString O ] */ duk_call_method(ctx, 0); return 1; }
static int r2plugin(duk_context *ctx) { RLibStruct *lib_struct; int ret = R_TRUE; // args: type, function const char *type = duk_require_string (ctx, 0); if (strcmp (type, "asm")) { eprintf ("TODO: duk.r2plugin only supports 'asm' plugins atm\n"); return R_FALSE; } // call function of 2nd parameter, or get object if (duk_is_function (ctx, 1)) { duk_push_string (ctx, "TODO"); // TODO: this must be the RAsm object to get bits, offset, .. duk_call (ctx, 1); duk_to_object (ctx, 1); } if (!duk_is_object (ctx, 1)) { eprintf ("Expected object or function\n"); return R_FALSE; } duk_to_object (ctx, 1); #define ap asm_plugin ap = R_NEW0 (RAsmPlugin); #define GETSTR(x,y,or) \ duk_dup_top (ctx); \ duk_get_prop_string (ctx, 1, y); \ if (or) { \ const char *str = duk_to_string (ctx, -1); \ x = mystrdup (str? str: or); \ } else { \ x = mystrdup (duk_require_string (ctx, -1)); \ } \ duk_pop (ctx); #define GETINT(x,y,or) \ duk_dup_top (ctx); \ duk_get_prop_string (ctx, 1, y); \ if (or) { \ x = duk_is_number (ctx, -1)? \ duk_to_int (ctx, -1): or; \ } else { \ x = duk_require_int (ctx, -1); \ } \ duk_pop (ctx); #define GETFUN(x,y) \ duk_dup_top (ctx); \ duk_get_prop_string (ctx, 1, y); \ x = duk_require_tval (ctx, 1); \ duk_pop (ctx); // mandatory GETSTR (ap->name, "name", NULL); GETSTR (ap->arch, "arch", NULL); // optional GETSTR (ap->license, "license", "unlicensed"); GETSTR (ap->desc, "description", "JS Disasm Plugin"); GETINT (ap->bits, "bits", 32); // mandatory unless we handle asm+disasm ap->user = duk_require_tval (ctx, -1); //ap->user = duk_dup_top (ctx); // clone object inside user //GETFUN (ap->user, "disassemble"); duk_push_global_stash(ctx); duk_get_prop_string (ctx, 1, "disassemble"); duk_put_prop_string(ctx, -2, "disfun"); // TODO: prefix plugin name somehow ap->disassemble = duk_disasm; duk_push_global_stash(ctx); duk_get_prop_string (ctx, 1, "assemble"); duk_put_prop_string(ctx, -2, "asmfun"); // TODO: prefix plugin name somehow ap->assemble = duk_assemble; #if 0 duk_get_prop_string (ctx, 1, "disassemble"); duk_push_string (ctx, "WINRAR"); duk_call (ctx, 1); #endif #if 0 duk_get_prop_string (ctx, 1, "disassemble"); void *a = duk_require_tval (ctx, -1); if (duk_is_callable (ctx, -1)) { ut8 *b = a; eprintf ("IS FUNCTION %02x %02x \n", b[0], b[1]); } else eprintf ("NOT CALLABLE\n"); ap->user = a; eprintf ("---- %p\n", a); duk_push_string (ctx, "F**K YOU"); //duk_dup_top(ctx); //duk_call_method (ctx, 0); duk_call (ctx, 1); duk_push_tval (ctx, ap->user); // push fun duk_push_string (ctx, "WINRAR"); duk_call (ctx, 1); duk_pop (ctx); #endif // TODO: add support to assemble from js too //ap->assemble = duk_disasm; #define lp lib_struct lp = R_NEW0 (RLibStruct); lp->type = R_LIB_TYPE_ASM; // TODO resolve from handler lp->data = ap; r_lib_open_ptr (Gcore->lib, "duktape.js", NULL, lp); duk_push_boolean (ctx, ret); 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; }
//void duk_to_object(duk_context *ctx, duk_idx_t index); void aperl_duk_to_object(duk_context *ctx, duk_idx_t index) { duk_to_object(ctx, index); }
DUK_INTERNAL duk_ret_t duk_bi_array_prototype_join_shared(duk_context *ctx) { duk_uint32_t len, count; duk_uint32_t idx; duk_small_int_t to_locale_string = duk_get_current_magic(ctx); duk_idx_t valstack_required; /* For join(), nargs is 1. For toLocaleString(), nargs is 0 and * setting the top essentially pushes an undefined to the stack, * thus defaulting to a comma separator. */ duk_set_top(ctx, 1); if (duk_is_undefined(ctx, 0)) { duk_pop(ctx); duk_push_hstring_stridx(ctx, DUK_STRIDX_COMMA); } else { duk_to_string(ctx, 0); } len = duk__push_this_obj_len_u32(ctx); /* [ sep ToObject(this) len ] */ DUK_DDD(DUK_DDDPRINT("sep=%!T, this=%!T, len=%lu", (duk_tval *) duk_get_tval(ctx, 0), (duk_tval *) duk_get_tval(ctx, 1), (unsigned long) len)); /* The extra (+4) is tight. */ valstack_required = (len >= DUK__ARRAY_MID_JOIN_LIMIT ? DUK__ARRAY_MID_JOIN_LIMIT : len) + 4; duk_require_stack(ctx, valstack_required); duk_dup(ctx, 0); /* [ sep ToObject(this) len sep ] */ count = 0; idx = 0; for (;;) { if (count >= DUK__ARRAY_MID_JOIN_LIMIT || /* intermediate join to avoid valstack overflow */ idx >= len) { /* end of loop (careful with len==0) */ /* [ sep ToObject(this) len sep str0 ... str(count-1) ] */ DUK_DDD(DUK_DDDPRINT("mid/final join, count=%ld, idx=%ld, len=%ld", (long) count, (long) idx, (long) len)); duk_join(ctx, (duk_idx_t) count); /* -> [ sep ToObject(this) len str ] */ duk_dup(ctx, 0); /* -> [ sep ToObject(this) len str sep ] */ duk_insert(ctx, -2); /* -> [ sep ToObject(this) len sep str ] */ count = 1; } if (idx >= len) { /* if true, the stack already contains the final result */ break; } duk_get_prop_index(ctx, 1, (duk_uarridx_t) idx); if (duk_is_null_or_undefined(ctx, -1)) { duk_pop(ctx); duk_push_hstring_stridx(ctx, DUK_STRIDX_EMPTY_STRING); } else { if (to_locale_string) { duk_to_object(ctx, -1); duk_get_prop_stridx(ctx, -1, DUK_STRIDX_TO_LOCALE_STRING); duk_insert(ctx, -2); /* -> [ ... toLocaleString ToObject(val) ] */ duk_call_method(ctx, 0); duk_to_string(ctx, -1); } else { duk_to_string(ctx, -1); } } count++; idx++; } /* [ sep ToObject(this) len sep result ] */ return 1; }
DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_context *ctx) { duk_small_uint_t pass; duk_uint_t defprop_flags; duk_hobject *obj; duk_idx_t idx_value; duk_hobject *get; duk_hobject *set; /* Lightfunc handling by ToObject() coercion. */ obj = duk_require_hobject_or_lfunc_coerce(ctx, 0); /* target */ DUK_ASSERT(obj != NULL); duk_to_object(ctx, 1); /* properties object */ DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", (duk_tval *) duk_get_tval(ctx, 0), (duk_tval *) duk_get_tval(ctx, 1))); /* * Two pass approach to processing the property descriptors. * On first pass validate and normalize all descriptors before * any changes are made to the target object. On second pass * make the actual modifications to the target object. * * Right now we'll just use the same normalize/validate helper * on both passes, ignoring its outputs on the first pass. */ for (pass = 0; pass < 2; pass++) { duk_set_top(ctx, 2); /* -> [ hobject props ] */ duk_enum(ctx, 1, DUK_ENUM_OWN_PROPERTIES_ONLY /*enum_flags*/); for (;;) { duk_hstring *key; /* [ hobject props enum(props) ] */ duk_set_top(ctx, 3); if (!duk_next(ctx, 2, 1 /*get_value*/)) { break; } DUK_DDD(DUK_DDDPRINT("-> key=%!iT, desc=%!iT", (duk_tval *) duk_get_tval(ctx, -2), (duk_tval *) duk_get_tval(ctx, -1))); /* [ hobject props enum(props) key desc ] */ duk_hobject_prepare_property_descriptor(ctx, 4 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* [ hobject props enum(props) key desc value? getter? setter? ] */ if (pass == 0) { continue; } key = duk_get_hstring(ctx, 3); DUK_ASSERT(key != NULL); duk_hobject_define_property_helper(ctx, defprop_flags, obj, key, idx_value, get, set); } } /* * Return target object */ duk_dup(ctx, 0); return 1; }
DUK_INTERNAL duk_ret_t duk_bi_object_constructor_define_properties(duk_hthread *thr) { duk_small_uint_t pass; duk_uint_t defprop_flags; duk_hobject *obj; duk_idx_t idx_value; duk_hobject *get; duk_hobject *set; /* Lightfunc and plain buffer handling by ToObject() coercion. */ obj = duk_require_hobject_promote_mask(thr, 0, DUK_TYPE_MASK_LIGHTFUNC | DUK_TYPE_MASK_BUFFER); DUK_ASSERT(obj != NULL); duk_to_object(thr, 1); /* properties object */ DUK_DDD(DUK_DDDPRINT("target=%!iT, properties=%!iT", (duk_tval *) duk_get_tval(thr, 0), (duk_tval *) duk_get_tval(thr, 1))); /* * Two pass approach to processing the property descriptors. * On first pass validate and normalize all descriptors before * any changes are made to the target object. On second pass * make the actual modifications to the target object. * * Right now we'll just use the same normalize/validate helper * on both passes, ignoring its outputs on the first pass. */ for (pass = 0; pass < 2; pass++) { duk_set_top(thr, 2); /* -> [ hobject props ] */ duk_enum(thr, 1, DUK_ENUM_OWN_PROPERTIES_ONLY | DUK_ENUM_INCLUDE_SYMBOLS /*enum_flags*/); for (;;) { duk_hstring *key; /* [ hobject props enum(props) ] */ duk_set_top(thr, 3); if (!duk_next(thr, 2, 1 /*get_value*/)) { break; } DUK_DDD(DUK_DDDPRINT("-> key=%!iT, desc=%!iT", (duk_tval *) duk_get_tval(thr, -2), (duk_tval *) duk_get_tval(thr, -1))); /* [ hobject props enum(props) key desc ] */ duk_hobject_prepare_property_descriptor(thr, 4 /*idx_desc*/, &defprop_flags, &idx_value, &get, &set); /* [ hobject props enum(props) key desc [multiple values] ] */ if (pass == 0) { continue; } /* This allows symbols on purpose. */ key = duk_known_hstring(thr, 3); DUK_ASSERT(key != NULL); duk_hobject_define_property_helper(thr, defprop_flags, obj, key, idx_value, get, set, 1 /*throw_flag*/); } } /* * Return target object */ duk_dup_0(thr); return 1; }