MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pass through active strict context

+38 -30
+11
include/silver/engine.h
··· 403 403 return false; 404 404 } 405 405 406 + static inline sv_vm_t *sv_vm_get_active(ant_t *js) { 407 + if (!js) return NULL; 408 + if (js->active_async_coro && js->active_async_coro->sv_vm) 409 + return js->active_async_coro->sv_vm; 410 + return js->vm; 411 + } 412 + 413 + static inline bool sv_is_strict_context(ant_t *js) { 414 + return sv_vm_is_strict(sv_vm_get_active(js)); 415 + } 416 + 406 417 static inline ant_value_t sv_vm_get_new_target(const sv_vm_t *vm, ant_t *js) { 407 418 if (vm && vm->fp >= 0) return vm->frames[vm->fp].new_target; 408 419 return js->new_target;
+27 -30
src/ant.c
··· 2973 2973 if (!ptr) return js_mkundef(); 2974 2974 2975 2975 if (ptr->frozen) { 2976 - return sv_vm_is_strict(js->vm) 2976 + return sv_is_strict_context(js) 2977 2977 ? js_mkerr(js, "cannot add property to frozen object") 2978 2978 : js_false; 2979 2979 } 2980 2980 2981 2981 if (ptr->sealed) { 2982 - return sv_vm_is_strict(js->vm) 2982 + return sv_is_strict_context(js) 2983 2983 ? js_mkerr(js, "cannot add property to sealed object") 2984 2984 : js_false; 2985 2985 } 2986 2986 2987 2987 if (!ptr->extensible) { 2988 - return sv_vm_is_strict(js->vm) 2988 + return sv_is_strict_context(js) 2989 2989 ? js_mkerr(js, "cannot add property to non-extensible object") 2990 2990 : js_false; 2991 2991 } ··· 3186 3186 } 3187 3187 } 3188 3188 3189 - if (sv_vm_is_strict(js->vm)) 3189 + if (sv_is_strict_context(js)) 3190 3190 return js_mkerr_typed(js, JS_ERR_TYPE, 3191 3191 "Cannot create property '%.*s' on %s", 3192 3192 (int)klen, key, typestr(ot)); ··· 3207 3207 if (meta.has_setter) { 3208 3208 ant_value_t setter = meta.setter; 3209 3209 if (vtype(setter) == T_FUNC || vtype(setter) == T_CFUNC) { 3210 - ant_value_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); 3210 + ant_value_t result = sv_vm_call(sv_vm_get_active(js), js, setter, obj, &v, 1, NULL, false); 3211 3211 if (is_err(result)) return result; 3212 3212 return v; 3213 3213 } 3214 3214 } 3215 3215 if (meta.has_getter && !meta.has_setter) { 3216 - if (sv_vm_is_strict(js->vm)) return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot set property which has only a getter"); 3216 + if (sv_is_strict_context(js)) return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot set property which has only a getter"); 3217 3217 return v; 3218 3218 } 3219 3219 if (!meta.has_getter && !meta.has_setter && !meta.writable) { 3220 - if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "assignment to read-only property"); 3220 + if (sv_is_strict_context(js)) return js_mkerr(js, "assignment to read-only property"); 3221 3221 return v; 3222 3222 } 3223 3223 break; ··· 3346 3346 uint8_t setter_type = vtype(setter); 3347 3347 if (setter_type == T_FUNC || setter_type == T_CFUNC) { 3348 3348 js_error_site_t saved_errsite = js->errsite; 3349 - ant_value_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); 3349 + ant_value_t result = sv_vm_call(sv_vm_get_active(js), js, setter, obj, &v, 1, NULL, false); 3350 3350 js->errsite = saved_errsite; 3351 3351 if (is_err(result)) return result; 3352 3352 return v; ··· 3354 3354 } 3355 3355 3356 3356 if (desc_has_getter && !desc_has_setter) { 3357 - if (sv_vm_is_strict(js->vm)) return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot set property which has only a getter"); 3357 + if (sv_is_strict_context(js)) return js_mkerr_typed(js, JS_ERR_TYPE, "Cannot set property which has only a getter"); 3358 3358 return v; 3359 3359 } 3360 3360 3361 3361 if (!desc_writable) { 3362 - if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "assignment to read-only property"); 3362 + if (sv_is_strict_context(js)) return js_mkerr(js, "assignment to read-only property"); 3363 3363 return v; 3364 3364 } 3365 3365 ··· 3440 3440 3441 3441 if (has_desc) { 3442 3442 if (!desc_writable && !desc_has_setter) { 3443 - if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "assignment to read-only property"); 3443 + if (sv_is_strict_context(js)) return js_mkerr(js, "assignment to read-only property"); 3444 3444 return v; 3445 3445 } 3446 3446 if (desc_has_setter) { 3447 3447 ant_value_t setter = desc_setter; 3448 3448 uint8_t setter_type = vtype(setter); 3449 3449 if (setter_type == T_FUNC || setter_type == T_CFUNC) { 3450 - ant_value_t result = sv_vm_call(js->vm, js, setter, obj, &v, 1, NULL, false); 3450 + ant_value_t result = sv_vm_call(sv_vm_get_active(js), js, setter, obj, &v, 1, NULL, false); 3451 3451 if (is_err(result)) return result; 3452 3452 return v; 3453 3453 } ··· 3771 3771 return 0; 3772 3772 } 3773 3773 3774 - static ant_value_t call_proto_accessor(ant_t *js, ant_value_t prim, ant_value_t accessor, bool has_accessor, ant_value_t *arg, int arg_count, bool is_setter) { 3775 - if (!has_accessor || (vtype(accessor) != T_FUNC && vtype(accessor) != T_CFUNC)) return js_mkundef(); 3774 + static ant_value_t call_proto_accessor( 3775 + ant_t *js, ant_value_t prim, ant_value_t accessor, bool has_accessor, 3776 + ant_value_t *arg, int arg_count, bool is_setter 3777 + ) { 3778 + if (!has_accessor || (vtype(accessor) != T_FUNC && vtype(accessor) != T_CFUNC)) 3779 + return js_mkundef(); 3776 3780 3777 3781 js_error_site_t saved_errsite = js->errsite; 3778 - ant_value_t result = sv_vm_call(js->vm, js, accessor, prim, arg, arg_count, NULL, false); 3782 + ant_value_t result = sv_vm_call(sv_vm_get_active(js), js, accessor, prim, arg, arg_count, NULL, false); 3779 3783 3780 3784 bool had_throw = js->thrown_exists; 3781 3785 ant_value_t thrown = js->thrown_value; ··· 4305 4309 if (!ptr) return js_mkundef(); 4306 4310 4307 4311 if (ptr->frozen) { 4308 - if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "cannot %s property of frozen object", action); 4312 + if (sv_is_strict_context(js)) return js_mkerr(js, "cannot %s property of frozen object", action); 4309 4313 return js_false; 4310 4314 } 4311 4315 if (ptr->sealed) { 4312 - if (sv_vm_is_strict(js->vm)) return js_mkerr(js, "cannot %s property of sealed object", action); 4316 + if (sv_is_strict_context(js)) return js_mkerr(js, "cannot %s property of sealed object", action); 4313 4317 return js_false; 4314 4318 } 4315 4319 return js_mkundef(); ··· 4329 4333 if (vtype(err) != T_UNDEF) return err; 4330 4334 4331 4335 if (array_obj_ptr(original_obj) && is_length_key(key, len)) { 4332 - if (sv_vm_is_strict(js->vm)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4336 + if (sv_is_strict_context(js)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4333 4337 return js_false; 4334 4338 } 4335 4339 ··· 4356 4360 4357 4361 uint8_t attrs = ant_shape_get_attrs(ptr->shape, (uint32_t)shape_slot); 4358 4362 if ((attrs & ANT_PROP_ATTR_CONFIGURABLE) == 0) { 4359 - if (sv_vm_is_strict(js->vm)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4363 + if (sv_is_strict_context(js)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4360 4364 return js_false; 4361 4365 } 4362 4366 4363 4367 if (ptr->is_exotic) { 4364 4368 descriptor_entry_t *desc = lookup_descriptor(obj, key, len); 4365 4369 if (desc && !desc->configurable) { 4366 - if (sv_vm_is_strict(js->vm)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4370 + if (sv_is_strict_context(js)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4367 4371 return js_false; 4368 4372 } 4369 4373 } ··· 4396 4400 4397 4401 uint8_t attrs = ant_shape_get_attrs(ptr->shape, (uint32_t)shape_slot); 4398 4402 if ((attrs & ANT_PROP_ATTR_CONFIGURABLE) == 0) { 4399 - if (sv_vm_is_strict(js->vm)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4403 + if (sv_is_strict_context(js)) return js_mkerr_typed(js, JS_ERR_TYPE, "cannot delete non-configurable property"); 4400 4404 return js_false; 4401 4405 } 4402 4406 ··· 11604 11608 return js_getstr(js, filename, NULL); 11605 11609 } 11606 11610 11607 - static sv_vm_t *js_get_active_vm(ant_t *js) { 11608 - if (!js) return NULL; 11609 - if (js->active_async_coro && js->active_async_coro->sv_vm) 11610 - return js->active_async_coro->sv_vm; 11611 - return js->vm; 11612 - } 11613 - 11614 11611 static ant_value_t js_module_ctx_from_func(ant_value_t func) { 11615 11612 if (vtype(func) != T_FUNC) return js_mkundef(); 11616 11613 ant_value_t module_ctx = get_slot(js_func_obj(func), SLOT_MODULE_CTX); ··· 11618 11615 } 11619 11616 11620 11617 static ant_value_t js_get_execution_module_ctx(ant_t *js) { 11621 - sv_vm_t *vm = js_get_active_vm(js); 11618 + sv_vm_t *vm = sv_vm_get_active(js); 11622 11619 if (vm && vm->fp >= 0) { 11623 11620 ant_value_t module_ctx = js_module_ctx_from_func(vm->frames[vm->fp].callee); 11624 11621 if (is_object_type(module_ctx)) return module_ctx; ··· 13330 13327 13331 13328 if (sv_dump_bytecode_unlikely) sv_disasm(js, func, js->filename); 13332 13329 if (func->is_tla) result = sv_execute_entry_tla(js, func, js->this_val); 13333 - else result = sv_execute_entry(js_get_active_vm(js), func, js->this_val, NULL, 0); 13330 + else result = sv_execute_entry(sv_vm_get_active(js), func, js->this_val, NULL, 0); 13334 13331 13335 13332 js->this_val = saved_this; 13336 13333 return result;