rm realm concept on function

This commit is contained in:
2026-02-05 02:33:50 -06:00
parent a98faa4dbb
commit cd21de3d70

View File

@@ -1564,7 +1564,6 @@ typedef struct JSFunction {
uint8_t kind; uint8_t kind;
union { union {
struct { struct {
JSContext *realm;
JSCFunctionType c_function; JSCFunctionType c_function;
uint8_t cproto; uint8_t cproto;
int16_t magic; int16_t magic;
@@ -1666,7 +1665,6 @@ typedef struct JSFunctionBytecode {
uint16_t var_count; uint16_t var_count;
uint16_t defined_arg_count; /* for length function property */ uint16_t defined_arg_count; /* for length function property */
uint16_t stack_size; /* maximum stack size */ uint16_t stack_size; /* maximum stack size */
JSContext *realm; /* function realm */
JSValue *cpool; /* constant pool (self pointer) */ JSValue *cpool; /* constant pool (self pointer) */
int cpool_count; int cpool_count;
int closure_var_count; int closure_var_count;
@@ -1774,6 +1772,7 @@ enum OPCodeEnum {
static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv); static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv);
static JSValue js_call_bound_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv); static JSValue js_call_bound_function (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv);
static JSValue JS_CallInternal (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags); static JSValue JS_CallInternal (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags);
static JSValue JS_CallInternalRegister(JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags);
int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop); int JS_DeleteProperty (JSContext *ctx, JSValue obj, JSValue prop);
JSValue __attribute__ ((format (printf, 2, 3))) JSValue __attribute__ ((format (printf, 2, 3)))
JS_ThrowInternalError (JSContext *ctx, const char *fmt, ...); JS_ThrowInternalError (JSContext *ctx, const char *fmt, ...);
@@ -3725,7 +3724,6 @@ static JSValue JS_NewCFunction3 (JSContext *ctx, JSCFunction *func, const char *
func_obj = js_new_function (ctx, JS_FUNC_KIND_C); func_obj = js_new_function (ctx, JS_FUNC_KIND_C);
if (JS_IsException (func_obj)) return func_obj; if (JS_IsException (func_obj)) return func_obj;
f = JS_VALUE_GET_FUNCTION (func_obj); f = JS_VALUE_GET_FUNCTION (func_obj);
f->u.cfunc.realm = ctx;
f->u.cfunc.c_function.generic = func; f->u.cfunc.c_function.generic = func;
f->u.cfunc.cproto = cproto; f->u.cfunc.cproto = cproto;
f->u.cfunc.magic = magic; f->u.cfunc.magic = magic;
@@ -6253,7 +6251,6 @@ static JSValue js_call_c_function (JSContext *ctx, JSValue func_obj, JSValue thi
prev_sf = rt->current_stack_frame; prev_sf = rt->current_stack_frame;
sf->prev_frame = prev_sf; sf->prev_frame = prev_sf;
rt->current_stack_frame = sf; rt->current_stack_frame = sf;
ctx = f->u.cfunc.realm; /* change the current realm */
sf->js_mode = 0; sf->js_mode = 0;
sf->cur_func = (JSValue)func_obj; sf->cur_func = (JSValue)func_obj;
sf->arg_count = argc; sf->arg_count = argc;
@@ -6389,7 +6386,7 @@ typedef enum {
/* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */ /* argv[] is modified if (flags & JS_CALL_FLAG_COPY_ARGV) = 0. */
static JSValue JS_CallInternal (JSContext *caller_ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags) { static JSValue JS_CallInternal (JSContext *caller_ctx, JSValue func_obj, JSValue this_obj, int argc, JSValue *argv, int flags) {
JSRuntime *rt = caller_ctx->rt; JSRuntime *rt = caller_ctx->rt;
JSContext *ctx; JSContext *ctx = caller_ctx;
JSFunction *f; JSFunction *f;
JSFunctionBytecode *b; JSFunctionBytecode *b;
JSStackFrame sf_s, *sf = &sf_s; JSStackFrame sf_s, *sf = &sf_s;
@@ -6516,7 +6513,6 @@ static JSValue JS_CallInternal (JSContext *caller_ctx, JSValue func_obj, JSValue
sf->p_sp = &sp; /* GC uses this to find current stack top */ sf->p_sp = &sp; /* GC uses this to find current stack top */
sf->prev_frame = rt->current_stack_frame; sf->prev_frame = rt->current_stack_frame;
rt->current_stack_frame = sf; rt->current_stack_frame = sf;
ctx = b->realm; /* set the current realm */
restart: restart:
for (;;) { for (;;) {
@@ -8252,35 +8248,6 @@ JSValue JS_Call (JSContext *ctx, JSValue func_obj, JSValue this_obj, int argc, J
return JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV); return JS_CallInternal (ctx, func_obj, this_obj, argc, (JSValue *)argv, JS_CALL_FLAG_COPY_ARGV);
} }
/* warning: the refcount of the context is not incremented. Return
NULL in case of exception (case of revoked proxy only) */
static JSContext *JS_GetFunctionRealm (JSContext *ctx, JSValue func_obj) {
JSFunction *f;
JSContext *realm;
if (JS_VALUE_GET_TAG (func_obj) != JS_TAG_FUNCTION) return ctx;
f = JS_VALUE_GET_FUNCTION (func_obj);
switch (f->kind) {
case JS_FUNC_KIND_C:
realm = f->u.cfunc.realm;
break;
case JS_FUNC_KIND_BYTECODE: {
JSFunctionBytecode *b;
b = f->u.func.function_bytecode;
realm = b->realm;
} break;
case JS_FUNC_KIND_BOUND: {
JSBoundFunction *bf = f->u.bound_function;
realm = JS_GetFunctionRealm (ctx, bf->func_obj);
} break;
case JS_FUNC_KIND_C_DATA:
default:
realm = ctx;
break;
}
return realm;
}
/* JS parser */ /* JS parser */
enum { enum {
@@ -16309,7 +16276,6 @@ static JSValue js_create_function (JSContext *ctx, JSFunctionDef *fd) {
/* IC removed - shapes no longer used */ /* IC removed - shapes no longer used */
b->is_direct_or_indirect_eval = FALSE; b->is_direct_or_indirect_eval = FALSE;
b->realm = ctx;
#if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 1) #if defined(DUMP_BYTECODE) && (DUMP_BYTECODE & 1)
if (!fd->strip_debug) { js_dump_function_bytecode (ctx, b); } if (!fd->strip_debug) { js_dump_function_bytecode (ctx, b); }
@@ -17892,7 +17858,6 @@ static JSValue JS_ReadFunctionTag (BCReaderState *s) {
} }
bc_read_trace (s, "}\n"); bc_read_trace (s, "}\n");
} }
b->realm = ctx;
return obj; return obj;
fail: fail:
return JS_EXCEPTION; return JS_EXCEPTION;
@@ -18752,7 +18717,6 @@ JSValue cell_module_integrate (JSContext *ctx, CellModule *mod, JSValue env) {
b->stack_size = cu->stack_size; b->stack_size = cu->stack_size;
b->cpool_count = cu->const_count; b->cpool_count = cu->const_count;
b->byte_code_len = cu->bytecode_len; b->byte_code_len = cu->bytecode_len;
b->realm = ctx;
/* Set up pointers */ /* Set up pointers */
b->cpool = (JSValue *)((uint8_t *)b + cpool_offset); b->cpool = (JSValue *)((uint8_t *)b + cpool_offset);