|
@ -418,7 +418,7 @@ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { |
|
|
num = (duk_small_uint_t) duk_bd_decode(bd, DUK__NUM_NORMAL_PROPS_BITS); |
|
|
num = (duk_small_uint_t) duk_bd_decode(bd, DUK__NUM_NORMAL_PROPS_BITS); |
|
|
DUK_DDD(DUK_DDDPRINT("built-in object %ld, %ld normal valued properties", (long) i, (long) num)); |
|
|
DUK_DDD(DUK_DDDPRINT("built-in object %ld, %ld normal valued properties", (long) i, (long) num)); |
|
|
for (j = 0; j < num; j++) { |
|
|
for (j = 0; j < num; j++) { |
|
|
duk_small_uint_t prop_flags; |
|
|
duk_small_uint_t defprop_flags; |
|
|
|
|
|
|
|
|
duk__push_stridx_or_string(ctx, bd); |
|
|
duk__push_stridx_or_string(ctx, bd); |
|
|
|
|
|
|
|
@ -430,15 +430,27 @@ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
if (duk_bd_decode_flag(bd)) { |
|
|
if (duk_bd_decode_flag(bd)) { |
|
|
prop_flags = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_FLAGS_BITS); |
|
|
defprop_flags = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_FLAGS_BITS); |
|
|
} else { |
|
|
} else { |
|
|
prop_flags = DUK_PROPDESC_FLAGS_WC; |
|
|
defprop_flags = DUK_PROPDESC_FLAGS_WC; |
|
|
} |
|
|
} |
|
|
|
|
|
defprop_flags |= DUK_DEFPROP_FORCE | |
|
|
|
|
|
DUK_DEFPROP_HAVE_VALUE | |
|
|
|
|
|
DUK_DEFPROP_HAVE_WRITABLE | |
|
|
|
|
|
DUK_DEFPROP_HAVE_ENUMERABLE | |
|
|
|
|
|
DUK_DEFPROP_HAVE_CONFIGURABLE; /* Defaults for data properties. */ |
|
|
|
|
|
|
|
|
|
|
|
/* The writable, enumerable, configurable flags in prop_flags
|
|
|
|
|
|
* match both duk_def_prop() and internal property flags. |
|
|
|
|
|
*/ |
|
|
|
|
|
DUK_ASSERT(DUK_PROPDESC_FLAG_WRITABLE == DUK_DEFPROP_WRITABLE); |
|
|
|
|
|
DUK_ASSERT(DUK_PROPDESC_FLAG_ENUMERABLE == DUK_DEFPROP_ENUMERABLE); |
|
|
|
|
|
DUK_ASSERT(DUK_PROPDESC_FLAG_CONFIGURABLE == DUK_DEFPROP_CONFIGURABLE); |
|
|
|
|
|
|
|
|
t = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_TYPE_BITS); |
|
|
t = (duk_small_uint_t) duk_bd_decode(bd, DUK__PROP_TYPE_BITS); |
|
|
|
|
|
|
|
|
DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld", |
|
|
DUK_DDD(DUK_DDDPRINT("built-in %ld, normal-valued property %ld, key %!T, flags 0x%02lx, type %ld", |
|
|
(long) i, (long) j, duk_get_tval(ctx, -1), (unsigned long) prop_flags, (long) t)); |
|
|
(long) i, (long) j, duk_get_tval(ctx, -1), (unsigned long) defprop_flags, (long) t)); |
|
|
|
|
|
|
|
|
switch (t) { |
|
|
switch (t) { |
|
|
case DUK__PROP_TYPE_DOUBLE: { |
|
|
case DUK__PROP_TYPE_DOUBLE: { |
|
@ -479,38 +491,28 @@ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { |
|
|
duk_c_function c_func_getter; |
|
|
duk_c_function c_func_getter; |
|
|
duk_c_function c_func_setter; |
|
|
duk_c_function c_func_setter; |
|
|
|
|
|
|
|
|
/* XXX: this is a bit awkward because there is no exposed helper
|
|
|
|
|
|
* in the API style, only this internal helper. |
|
|
|
|
|
*/ |
|
|
|
|
|
DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", |
|
|
DUK_DDD(DUK_DDDPRINT("built-in accessor property: objidx=%ld, key=%!T, getteridx=%ld, setteridx=%ld, flags=0x%04lx", |
|
|
(long) i, duk_get_tval(ctx, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) prop_flags)); |
|
|
(long) i, duk_get_tval(ctx, -1), (long) natidx_getter, (long) natidx_setter, (unsigned long) defprop_flags)); |
|
|
|
|
|
|
|
|
c_func_getter = duk_bi_native_functions[natidx_getter]; |
|
|
c_func_getter = duk_bi_native_functions[natidx_getter]; |
|
|
c_func_setter = duk_bi_native_functions[natidx_setter]; |
|
|
|
|
|
if (c_func_getter != NULL) { |
|
|
if (c_func_getter != NULL) { |
|
|
duk_push_c_function_noconstruct_noexotic(ctx, c_func_getter, 0); /* always 0 args */ |
|
|
duk_push_c_function_noconstruct_noexotic(ctx, c_func_getter, 0); /* always 0 args */ |
|
|
} else { |
|
|
defprop_flags |= DUK_DEFPROP_HAVE_GETTER; |
|
|
duk_push_undefined(ctx); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
c_func_setter = duk_bi_native_functions[natidx_setter]; |
|
|
if (c_func_setter != NULL) { |
|
|
if (c_func_setter != NULL) { |
|
|
duk_push_c_function_noconstruct_noexotic(ctx, c_func_setter, 1); /* always 1 arg */ |
|
|
duk_push_c_function_noconstruct_noexotic(ctx, c_func_setter, 1); /* always 1 arg */ |
|
|
} else { |
|
|
defprop_flags |= DUK_DEFPROP_HAVE_SETTER; |
|
|
duk_push_undefined(ctx); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* XXX: magic for getter/setter? use duk_def_prop()? */ |
|
|
/* XXX: magic for getter/setter? */ |
|
|
|
|
|
|
|
|
DUK_ASSERT((prop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ |
|
|
/* Writable flag doesn't make sense for an accessor. */ |
|
|
|
|
|
DUK_ASSERT((defprop_flags & DUK_PROPDESC_FLAG_WRITABLE) == 0); /* genbuiltins.py ensures */ |
|
|
|
|
|
|
|
|
prop_flags |= DUK_PROPDESC_FLAG_ACCESSOR; /* accessor flag not encoded explicitly */ |
|
|
defprop_flags &= ~(DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); |
|
|
duk_hobject_define_accessor_internal(thr, |
|
|
defprop_flags |= DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_HAVE_CONFIGURABLE; |
|
|
duk_require_hobject(ctx, i), |
|
|
break; |
|
|
duk_get_hstring(ctx, -3), |
|
|
|
|
|
duk_get_hobject(ctx, -2), |
|
|
|
|
|
duk_get_hobject(ctx, -1), |
|
|
|
|
|
prop_flags); |
|
|
|
|
|
duk_pop_3(ctx); /* key, getter and setter, now reachable through object */ |
|
|
|
|
|
goto skip_value; |
|
|
|
|
|
} |
|
|
} |
|
|
default: { |
|
|
default: { |
|
|
/* exhaustive */ |
|
|
/* exhaustive */ |
|
@ -518,11 +520,8 @@ DUK_INTERNAL void duk_hthread_create_builtin_objects(duk_hthread *thr) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
DUK_ASSERT((prop_flags & DUK_PROPDESC_FLAG_ACCESSOR) == 0); |
|
|
duk_def_prop(ctx, i, defprop_flags); |
|
|
duk_xdef_prop(ctx, i, prop_flags); |
|
|
DUK_ASSERT_TOP(ctx, DUK_NUM_ALL_BUILTINS); |
|
|
|
|
|
|
|
|
skip_value: |
|
|
|
|
|
continue; /* avoid empty label at the end of a compound statement */ |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* native function properties */ |
|
|
/* native function properties */ |
|
|