Skip to content

Commit

Permalink
Fix wrong code order in opfunc_in (#2390)
Browse files Browse the repository at this point in the history
Also no conversion if the left value is a string.

Fixes #2386.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
  • Loading branch information
zherczeg authored and yichoi committed Jun 11, 2018
1 parent d637e31 commit bd0ea4f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
23 changes: 17 additions & 6 deletions jerry-core/vm/opcodes-ecma-relational-equality.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,29 @@ opfunc_in (ecma_value_t left_value, /**< left value */
return ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object in 'in' check."));
}

ecma_value_t left_string_value = ecma_op_to_string (left_value);
if (ECMA_IS_VALUE_ERROR (left_string_value))
bool to_string = !ecma_is_value_string (left_value);

if (to_string)
{
return left_string_value;
left_value = ecma_op_to_string (left_value);

if (ECMA_IS_VALUE_ERROR (left_value))
{
return left_value;
}
}

ecma_string_t *left_value_prop_name_p = ecma_get_string_from_value (left_string_value);
ecma_string_t *left_value_prop_name_p = ecma_get_string_from_value (left_value);
ecma_object_t *right_value_obj_p = ecma_get_object_from_value (right_value);

ecma_free_value (left_string_value);
ecma_value_t result = ecma_make_boolean_value (ecma_op_object_has_property (right_value_obj_p,
left_value_prop_name_p));

return ecma_make_boolean_value (ecma_op_object_has_property (right_value_obj_p, left_value_prop_name_p));
if (to_string)
{
ecma_free_value (left_value);
}
return result;
} /* opfunc_in */

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/jerry/regression-test-issue-2386.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Math in Number

0 comments on commit bd0ea4f

Please sign in to comment.