HasInstance should accept the prototype of all functions. Fixes #1519. (#1520)

The regression-test-issue-736.js is also changed, since it expects
throwing an error, which does not happen anymore because the "x"
variable is undefined.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2017-01-16 13:43:54 +01:00
committed by Tilmann Scheller
parent 6e5b759319
commit 4b5cf8ad26
3 changed files with 47 additions and 13 deletions
@@ -366,14 +366,9 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
ecma_value_t ret_value = ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY);
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION)
if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_FUNCTION
|| ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION)
{
if (ecma_get_object_is_builtin (func_obj_p)
&& ecma_builtin_function_is_routine (func_obj_p))
{
return ecma_raise_type_error (ECMA_ERR_MSG ("Function parameter cannot be built-in a function."));
}
if (!ecma_is_value_object (value))
{
return ecma_make_simple_value (ECMA_SIMPLE_VALUE_FALSE);
@@ -389,7 +384,7 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
if (!ecma_is_value_object (prototype_obj_value))
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Expected an object."));
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Object expected."));
}
else
{
@@ -419,10 +414,6 @@ ecma_op_function_has_instance (ecma_object_t *func_obj_p, /**< Function object *
ecma_deref_ecma_string (prototype_magic_string_p);
}
else if (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_EXTERNAL_FUNCTION)
{
ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Expected a function."));
}
else
{
JERRY_ASSERT (ecma_get_object_type (func_obj_p) == ECMA_OBJECT_TYPE_BOUND_FUNCTION);
+43
View File
@@ -0,0 +1,43 @@
// 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.
try {
({} instanceof assert);
assert(false);
} catch(e) {
assert(e instanceof TypeError);
}
assert.prototype = {}
try {
assert(!({} instanceof assert));
} catch(e) {
assert(false);
}
try {
({} instanceof Math.sin);
assert(false);
} catch(e) {
assert(e instanceof TypeError);
}
Math.sin.prototype = {}
try {
assert(!({} instanceof Math.sin));
} catch(e) {
assert(false);
}
+1 -1
View File
@@ -31,7 +31,7 @@ try {
}
try {
eval("var x; x instanceof assert;");
eval("var x = {}; x instanceof assert;");
assert(false);
} catch(e) {
assert(e instanceof TypeError);