string indexing
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -3193,6 +3193,9 @@ JSValue JS_GetPropertyValue (JSContext *ctx, JSValue this_obj, JSValue prop) {
|
||||
}
|
||||
|
||||
JSValue JS_SetPropertyNumber (JSContext *js, JSValue obj, int idx, JSValue val) {
|
||||
if (JS_IsText (obj)) {
|
||||
return JS_ThrowTypeError (js, "strings are immutable");
|
||||
}
|
||||
if (!JS_IsArray (obj)) {
|
||||
return JS_ThrowInternalError (js,
|
||||
"cannot set with a number on a non array");
|
||||
@@ -3225,7 +3228,7 @@ JSValue JS_GetPropertyNumber (JSContext *js, JSValue obj, int idx) {
|
||||
if (JS_IsText (obj)) {
|
||||
uint32_t len = js_string_get_length (obj);
|
||||
if (idx < 0 || (uint32_t)idx >= len) { return JS_NULL; }
|
||||
return js_sub_string (js, JS_VALUE_GET_STRING (obj), idx, idx + 1);
|
||||
return js_sub_string_val (js, obj, idx, idx + 1);
|
||||
}
|
||||
|
||||
return JS_NULL;
|
||||
|
||||
Reference in New Issue
Block a user