string indexing

This commit is contained in:
2026-02-09 11:17:42 -06:00
parent e04ab4c30c
commit bc87fe5f70
2 changed files with 19 additions and 3 deletions

View File

@@ -1932,8 +1932,21 @@ JSValue mcode_exec(JSContext *ctx, JSMCode *code, JSValue this_obj,
if (iname) {
JSValue key = JS_NewString(ctx, iname);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
JSValue val = JS_GetProperty(ctx, ctx->global_obj, key);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
/* Try env (outer_frame) first, then global */
JSFunction *cur_fn = JS_VALUE_GET_FUNCTION(frame->function);
JSValue env = (cur_fn && cur_fn->kind == JS_FUNC_KIND_MCODE)
? cur_fn->u.mcode.outer_frame : JS_NULL;
JSValue val = JS_NULL;
if (!JS_IsNull(env)) {
val = JS_GetProperty(ctx, env, key);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
}
if (JS_IsNull(val)) {
key = JS_NewString(ctx, iname);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
val = JS_GetProperty(ctx, ctx->global_obj, key);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);
}
if (JS_IsNull(val)) {
key = JS_NewString(ctx, iname);
frame = (JSFrameRegister *)JS_VALUE_GET_PTR(frame_ref.val);