diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c index 0b07ec67e..6b10200ee 100644 --- a/src/njs_vmcode.c +++ b/src/njs_vmcode.c @@ -700,7 +700,7 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap, ret = njs_object_prop_define(vm, value1, &name, function, accessor->type); if (njs_slow_path(ret != NJS_OK)) { - return NJS_ERROR; + goto error; } ret = sizeof(njs_vmcode_prop_accessor_t); @@ -779,12 +779,12 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap, } if (njs_slow_path(!njs_is_function(&dst))) { - ret = njs_value_to_key(vm, value2, value2); + ret = njs_value_to_key(vm, &dst, value2); if (njs_slow_path(ret != NJS_OK)) { - return NJS_ERROR; + goto error; } - njs_key_string_get(vm, value2, &string); + njs_key_string_get(vm, &dst, &string); njs_type_error(vm, "(intermediate value)[\"%V\"] is not a function", &string); @@ -950,7 +950,8 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap, if (njs_is_valid(value1)) { value1 = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t)); if (njs_slow_path(value1 == NULL)) { - return NJS_ERROR; + njs_memory_error(vm); + goto error; } njs_scope_value_set(vm, var->dst, value1); @@ -967,7 +968,8 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, void *promise_cap, value1 = njs_mp_alloc(vm->mem_pool, sizeof(njs_value_t)); if (njs_slow_path(value1 == NULL)) { - return NJS_ERROR; + njs_memory_error(vm); + goto error; } *value1 = *value2; diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index ef5b3ca45..186defa1a 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -3409,6 +3409,11 @@ static njs_unit_test_t njs_test[] = /**/ + { njs_str("function f() { Object.prototype.toString = 1; };" + "Object.prototype.toString = f;" + "(function () { try { 's'[{}](); } catch (e) { throw e; } })()"), + njs_str("TypeError: Cannot convert object to primitive value") }, + { njs_str("var i; for (i = 0; i < 10; i++) { i += 1 } i"), njs_str("10") },