Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r 0cfc9e7f4b68 njs/njs_value.c
- --- a/njs/njs_value.c Fri Jul 05 21:45:28 2019 +0300
- +++ b/njs/njs_value.c Wed Jul 10 04:52:37 2019 -0400
- @@ -173,7 +173,7 @@ njs_value_to_primitive(njs_vm_t *vm, njs
- nxt_uint_t hint)
- {
- njs_ret_t ret;
- - nxt_uint_t trap_tries;
- + nxt_uint_t tries;
- njs_value_t retval;
- njs_object_prop_t *prop;
- nxt_lvlhsh_query_t lhq;
- @@ -195,13 +195,13 @@ njs_value_to_primitive(njs_vm_t *vm, njs
- return NXT_OK;
- }
- - trap_tries = 0;
- + tries = 0;
- for ( ;; ) {
- ret = NXT_ERROR;
- - if (njs_is_object(value) && trap_tries < 2) {
- - hint ^= trap_tries++;
- + if (njs_is_object(value) && tries < 2) {
- + hint ^= tries++;
- lhq.key_hash = hashes[hint];
- lhq.key = names[hint];
- diff -r 0cfc9e7f4b68 njs/njs_vm.c
- --- a/njs/njs_vm.c Fri Jul 05 21:45:28 2019 +0300
- +++ b/njs/njs_vm.c Wed Jul 10 04:52:37 2019 -0400
- @@ -127,6 +127,8 @@ start:
- for ( ;; ) {
- frame = (njs_frame_t *) vm->top_frame;
- +
- + call = frame->native.call;
- catch = frame->native.exception.catch;
- if (catch != NULL) {
- @@ -152,8 +154,6 @@ start:
- njs_vm_scopes_restore(vm, frame, previous);
- - call = frame->native.call;
- -
- if (frame->native.size != 0) {
- vm->stack_size -= frame->native.size;
- nxt_mp_free(vm->mem_pool, frame);
- @@ -162,7 +162,6 @@ start:
- if (call) {
- return NXT_ERROR;
- }
- -
- }
- }
- @@ -852,13 +851,6 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs
- }
- -/*
- - * The increment and decrement operations require only one value parameter.
- - * However, if the value is not numeric, then the trap is generated and
- - * value parameter points to a trap frame value converted to a numeric.
- - * So the additional reference parameter points to the original value.
- - */
- -
- njs_ret_t
- njs_vmcode_increment(njs_vm_t *vm, njs_value_t *reference, njs_value_t *value)
- {
- @@ -1188,28 +1180,43 @@ njs_string_concat(njs_vm_t *vm, njs_valu
- }
- +nxt_inline njs_ret_t
- +njs_values_to_numberic(njs_vm_t *vm, njs_value_t *numeric1, njs_value_t **val1,
- + njs_value_t *numeric2, njs_value_t **val2)
- +{
- + njs_ret_t ret;
- +
- + if (nxt_slow_path(!njs_is_numeric(*val1))) {
- + ret = njs_value_to_numeric(vm, numeric1, *val1);
- + if (ret != NXT_OK) {
- + return ret;
- + }
- +
- + *val1 = numeric1;
- + }
- +
- + if (nxt_slow_path(!njs_is_numeric(*val2))) {
- + ret = njs_value_to_numeric(vm, numeric2, *val2);
- + if (ret != NXT_OK) {
- + return ret;
- + }
- +
- + *val2 = numeric2;
- + }
- +
- + return NXT_OK;
- +}
- +
- +
- njs_ret_t
- njs_vmcode_substraction(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
- {
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- njs_set_number(&vm->retval, njs_number(val1) - njs_number(val2));
- @@ -1224,22 +1231,9 @@ njs_vmcode_multiplication(njs_vm_t *vm,
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- njs_set_number(&vm->retval, njs_number(val1) * njs_number(val2));
- @@ -1256,22 +1250,9 @@ njs_vmcode_exponentiation(njs_vm_t *vm,
- nxt_bool_t valid;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- base = njs_number(val1);
- @@ -1304,22 +1285,9 @@ njs_vmcode_division(njs_vm_t *vm, njs_va
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- njs_set_number(&vm->retval, njs_number(val1) / njs_number(val2));
- @@ -1331,28 +1299,17 @@ njs_vmcode_division(njs_vm_t *vm, njs_va
- njs_ret_t
- njs_vmcode_remainder(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
- {
- + double num;
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- - }
- -
- - njs_set_number(&vm->retval, fmod(njs_number(val1), njs_number(val2)));
- + num = fmod(njs_number(val1), njs_number(val2));
- + njs_set_number(&vm->retval, num);
- return sizeof(njs_vmcode_3addr_t);
- }
- @@ -1366,22 +1323,9 @@ njs_vmcode_left_shift(njs_vm_t *vm, njs_
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- num1 = njs_number_to_int32(njs_number(val1));
- @@ -1400,22 +1344,9 @@ njs_vmcode_right_shift(njs_vm_t *vm, njs
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- num1 = njs_number_to_int32(njs_number(val1));
- @@ -1434,22 +1365,9 @@ njs_vmcode_unsigned_right_shift(njs_vm_t
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- num1 = njs_number_to_uint32(njs_number(val1));
- @@ -1529,22 +1447,9 @@ njs_vmcode_bitwise_and(njs_vm_t *vm, njs
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- num1 = njs_number_to_integer(njs_number(val1));
- @@ -1562,22 +1467,9 @@ njs_vmcode_bitwise_xor(njs_vm_t *vm, njs
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- num1 = njs_number_to_integer(njs_number(val1));
- @@ -1595,22 +1487,9 @@ njs_vmcode_bitwise_or(njs_vm_t *vm, njs_
- njs_ret_t ret;
- njs_value_t numeric1, numeric2;
- - if (nxt_slow_path(!njs_is_numeric(val1))) {
- - ret = njs_value_to_numeric(vm, &numeric1, val1);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val1 = &numeric1;
- - }
- -
- - if (nxt_slow_path(!njs_is_numeric(val2))) {
- - ret = njs_value_to_numeric(vm, &numeric2, val2);
- - if (ret != NXT_OK) {
- - return ret;
- - }
- -
- - val2 = &numeric2;
- + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
- + if (ret != NXT_OK) {
- + return ret;
- }
- num1 = njs_number_to_integer(njs_number(val1));
- @@ -2137,7 +2016,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n
- njs_ret_t
- njs_vmcode_return(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
- {
- - uint8_t call;
- + nxt_int_t ret;
- njs_value_t *value;
- njs_frame_t *frame;
- njs_native_frame_t *previous;
- @@ -2170,11 +2049,11 @@ njs_vmcode_return(njs_vm_t *vm, njs_valu
- vm->current = frame->return_address;
- - call = frame->native.call;
- + ret = frame->native.call ? NJS_STOP : 0;
- njs_function_frame_free(vm, &frame->native);
- - return call ? NJS_STOP : 0;
- + return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement