JavaScript-Embedded
view release on metacpan or search on metacpan
lib/JavaScript/Embedded/C/lib/duktape.c view on Meta::CPAN
(duk_tval *) duk_require_tval(thr, idx_value)));
/* strict flag for putvar comes from our caller (currently: fixed) */
duk_js_putvar_envrec(thr, varenv, varname, duk_require_tval(thr, idx_value), 1 /*throw_flag*/);
}
if (has_writable && !is_writable) {
DUK_DDD(DUK_DDDPRINT("defineProperty successful, key mapped to arguments 'map', "
"changed to non-writable, delete arguments binding"));
(void) duk_hobject_delprop_raw(thr, map, key, 0); /* ignore result */
}
}
/* 'varname' is in stack in this else branch, leaving an unbalanced stack below,
* but this doesn't matter now.
*/
}
success_no_exotics:
/* Some code paths use NORZ macros for simplicity, ensure refzero
* handling is completed.
*/
DUK_REFZERO_CHECK_SLOW(thr);
return 1;
fail_not_extensible:
if (throw_flag) {
DUK_ERROR_TYPE(thr, DUK_STR_NOT_EXTENSIBLE);
DUK_WO_NORETURN(return 0;);
}
return 0;
fail_virtual: /* just use the same "not configurable" error message" */
fail_not_configurable:
if (throw_flag) {
DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE);
DUK_WO_NORETURN(return 0;);
}
return 0;
}
/*
* Object.prototype.hasOwnProperty() and Object.prototype.propertyIsEnumerable().
*/
DUK_INTERNAL duk_bool_t duk_hobject_object_ownprop_helper(duk_hthread *thr, duk_small_uint_t required_desc_flags) {
duk_hstring *h_v;
duk_hobject *h_obj;
duk_propdesc desc;
duk_bool_t ret;
/* coercion order matters */
h_v = duk_to_hstring_acceptsymbol(thr, 0);
DUK_ASSERT(h_v != NULL);
h_obj = duk_push_this_coercible_to_object(thr);
DUK_ASSERT(h_obj != NULL);
ret = duk_hobject_get_own_propdesc(thr, h_obj, h_v, &desc, 0 /*flags*/); /* don't push value */
duk_push_boolean(thr, ret && ((desc.flags & required_desc_flags) == required_desc_flags));
return 1;
}
/*
* Object.seal() and Object.freeze() (E5 Sections 15.2.3.8 and 15.2.3.9)
*
* Since the algorithms are similar, a helper provides both functions.
* Freezing is essentially sealing + making plain properties non-writable.
*
* Note: virtual (non-concrete) properties which are non-configurable but
* writable would pose some problems, but such properties do not currently
* exist (all virtual properties are non-configurable and non-writable).
* If they did exist, the non-configurability does NOT prevent them from
* becoming non-writable. However, this change should be recorded somehow
* so that it would turn up (e.g. when getting the property descriptor),
* requiring some additional flags in the object.
*/
DUK_INTERNAL void duk_hobject_object_seal_freeze_helper(duk_hthread *thr, duk_hobject *obj, duk_bool_t is_freeze) {
duk_uint_fast32_t i;
DUK_ASSERT(thr != NULL);
DUK_ASSERT(thr->heap != NULL);
DUK_ASSERT(obj != NULL);
DUK_ASSERT_VALSTACK_SPACE(thr, DUK__VALSTACK_SPACE);
#if defined(DUK_USE_ROM_OBJECTS)
if (DUK_HEAPHDR_HAS_READONLY((duk_heaphdr *) obj)) {
DUK_DD(DUK_DDPRINT("attempt to seal/freeze a readonly object, reject"));
DUK_ERROR_TYPE(thr, DUK_STR_NOT_CONFIGURABLE);
DUK_WO_NORETURN(return;);
}
#endif
/*
* Abandon array part because all properties must become non-configurable.
* Note that this is now done regardless of whether this is always the case
* (skips check, but performance problem if caller would do this many times
* for the same object; not likely).
*/
duk__abandon_array_part(thr, obj);
DUK_ASSERT(DUK_HOBJECT_GET_ASIZE(obj) == 0);
for (i = 0; i < DUK_HOBJECT_GET_ENEXT(obj); i++) {
duk_uint8_t *fp;
/* since duk__abandon_array_part() causes a resize, there should be no gaps in keys */
DUK_ASSERT(DUK_HOBJECT_E_GET_KEY(thr->heap, obj, i) != NULL);
/* avoid multiple computations of flags address; bypasses macros */
fp = DUK_HOBJECT_E_GET_FLAGS_PTR(thr->heap, obj, i);
if (is_freeze && !((*fp) & DUK_PROPDESC_FLAG_ACCESSOR)) {
*fp &= ~(DUK_PROPDESC_FLAG_WRITABLE | DUK_PROPDESC_FLAG_CONFIGURABLE);
} else {
*fp &= ~DUK_PROPDESC_FLAG_CONFIGURABLE;
}
}
( run in 2.648 seconds using v1.01-cache-2.11-cpan-d8267643d1d )