diff options
Diffstat (limited to 'src/njs_vmcode.c')
-rw-r--r-- | src/njs_vmcode.c | 117 |
1 files changed, 60 insertions, 57 deletions
diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c index 3826f9eb..727dc6d0 100644 --- a/src/njs_vmcode.c +++ b/src/njs_vmcode.c @@ -16,15 +16,12 @@ struct njs_property_next_s { static njs_jump_off_t njs_vmcode_object(njs_vm_t *vm, njs_value_t *retval); static njs_jump_off_t njs_vmcode_array(njs_vm_t *vm, u_char *pc, njs_value_t *retval); -static njs_jump_off_t njs_vmcode_function(njs_vm_t *vm, u_char *pc, - njs_value_t *retval); +static njs_jump_off_t njs_vmcode_function(njs_vm_t *vm, u_char *pc); static njs_jump_off_t njs_vmcode_arguments(njs_vm_t *vm, u_char *pc); static njs_jump_off_t njs_vmcode_regexp(njs_vm_t *vm, u_char *pc, njs_value_t *retval); static njs_jump_off_t njs_vmcode_template_literal(njs_vm_t *vm, njs_value_t *retval); -static njs_jump_off_t njs_vmcode_function_copy(njs_vm_t *vm, njs_value_t *value, - njs_index_t retval); static njs_jump_off_t njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *key, njs_value_t *retval); @@ -113,7 +110,6 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, njs_value_t *rval, njs_vmcode_equal_jump_t *equal; njs_vmcode_try_return_t *try_return; njs_vmcode_method_frame_t *method_frame; - njs_vmcode_function_copy_t *fcopy; njs_vmcode_prop_accessor_t *accessor; njs_vmcode_try_trampoline_t *try_trampoline; njs_vmcode_function_frame_t *function_frame; @@ -157,7 +153,6 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_char *pc, njs_value_t *rval, NJS_GOTO_ROW(NJS_VMCODE_IF_EQUAL_JUMP), NJS_GOTO_ROW(NJS_VMCODE_PROPERTY_INIT), NJS_GOTO_ROW(NJS_VMCODE_RETURN), - NJS_GOTO_ROW(NJS_VMCODE_FUNCTION_COPY), NJS_GOTO_ROW(NJS_VMCODE_FUNCTION_FRAME), NJS_GOTO_ROW(NJS_VMCODE_METHOD_FRAME), NJS_GOTO_ROW(NJS_VMCODE_FUNCTION_CALL), @@ -672,14 +667,52 @@ NEXT_LBL; src = value1; } - ret = njs_primitive_value_to_string(vm, &dst, src); - if (njs_slow_path(ret != NJS_OK)) { - goto error; - } + if (njs_is_number(src)) { + size_t size; + njs_string_t sp; + char buf[64]; - ret = njs_string_concat(vm, s1, s2, &name); - if (njs_slow_path(ret == NJS_ERROR)) { - goto error; + /* Alloc free path for "str" + int or int + "str" concatenation. */ + + num = njs_number(src); + + if (isnan(num)) { + njs_atom_to_value(vm, &dst, NJS_ATOM_STRING_NaN); + + } else if (isinf(num)) { + + if (num < 0) { + njs_atom_to_value(vm, &dst, NJS_ATOM_STRING__Infinity); + + } else { + njs_atom_to_value(vm, &dst, NJS_ATOM_STRING_Infinity); + } + + } else { + size = njs_dtoa(num, buf); + + sp.start = (u_char *) buf; + sp.size = size; + sp.length = size; + + dst.string.data = &sp; + } + + ret = njs_string_concat(vm, s1, s2, &name); + if (njs_slow_path(ret == NJS_ERROR)) { + goto error; + } + + } else { + ret = njs_primitive_value_to_string(vm, &dst, src); + if (njs_slow_path(ret != NJS_OK)) { + goto error; + } + + ret = njs_string_concat(vm, s1, s2, &name); + if (njs_slow_path(ret == NJS_ERROR)) { + goto error; + } } njs_value_assign(retval, &name); @@ -1155,9 +1188,7 @@ NEXT_LBL; CASE (NJS_VMCODE_FUNCTION): njs_vmcode_debug_opcode(); - njs_vmcode_operand(vm, vmcode->operand1, retval); - - ret = njs_vmcode_function(vm, pc, retval); + ret = njs_vmcode_function(vm, pc); if (njs_slow_path(ret < 0 && ret >= NJS_PREEMPT)) { goto error; } @@ -1422,17 +1453,6 @@ NEXT_LBL; return NJS_OK; - CASE (NJS_VMCODE_FUNCTION_COPY): - njs_vmcode_debug_opcode(); - - fcopy = (njs_vmcode_function_copy_t *) pc; - ret = njs_vmcode_function_copy(vm, fcopy->function, fcopy->retval); - if (njs_slow_path(ret == NJS_ERROR)) { - goto error; - } - - BREAK; - CASE (NJS_VMCODE_FUNCTION_FRAME): njs_vmcode_debug_opcode(); @@ -1928,7 +1948,7 @@ njs_vmcode_array(njs_vm_t *vm, u_char *pc, njs_value_t *retval) static njs_jump_off_t -njs_vmcode_function(njs_vm_t *vm, u_char *pc, njs_value_t *retval) +njs_vmcode_function(njs_vm_t *vm, u_char *pc) { njs_function_t *function; njs_vmcode_function_t *code; @@ -1948,7 +1968,7 @@ njs_vmcode_function(njs_vm_t *vm, u_char *pc, njs_value_t *retval) function->args_count = lambda->nargs - lambda->rest_parameters; - njs_set_function(retval, function); + njs_set_function(njs_scope_value(vm, code->retval), function); return sizeof(njs_vmcode_function_t); } @@ -2028,28 +2048,9 @@ njs_vmcode_template_literal(njs_vm_t *vm, njs_value_t *retval) return ret; } - return sizeof(njs_vmcode_template_literal_t); -} - - -static njs_jump_off_t -njs_vmcode_function_copy(njs_vm_t *vm, njs_value_t *value, njs_index_t retidx) -{ - njs_value_t *retval; - njs_function_t *function; - - retval = njs_scope_value(vm, retidx); - - if (!njs_is_valid(retval)) { - *retval = *value; - - function = njs_function_value_copy(vm, retval); - if (njs_slow_path(function == NULL)) { - return NJS_ERROR; - } - } + njs_array_destroy(vm, array); - return sizeof(njs_vmcode_function_copy_t); + return sizeof(njs_vmcode_template_literal_t); } @@ -2122,12 +2123,6 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *key, } } - prop = njs_object_prop_alloc(vm, init, 1); - if (njs_slow_path(prop == NULL)) { - return NJS_ERROR; - } - - lhq.value = prop; lhq.key_hash = name.atom_id; lhq.replace = 1; lhq.pool = vm->mem_pool; @@ -2139,6 +2134,14 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *key, return NJS_ERROR; } + prop = lhq.value; + + prop->type = NJS_PROPERTY; + prop->enumerable = 1; + prop->configurable = 1; + prop->writable = 1; + prop->u.value = *init; + break; default: @@ -2591,7 +2594,7 @@ njs_function_frame_create(njs_vm_t *vm, njs_value_t *value, } -inline njs_object_t * +njs_object_t * njs_function_new_object(njs_vm_t *vm, njs_value_t *constructor) { njs_value_t proto, bound; |