diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c index 6355239e35..a23dadf0a2 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-object.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-object.c @@ -14,7 +14,6 @@ */ #include "ecma-alloc.h" -#include "ecma-array-object.h" #include "ecma-builtin-helpers.h" #include "ecma-builtins.h" #include "ecma-conversion.h" @@ -109,27 +108,38 @@ ecma_builtin_object_object_get_prototype_of (ecma_value_t this_arg, /**< 'this' { JERRY_UNUSED (this_arg); ecma_value_t ret_value = ECMA_VALUE_EMPTY; + bool was_object = ecma_is_value_object (arg); /* 1. */ - if (!ecma_is_value_object (arg)) + if (!was_object) { - ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object.")); +#ifndef CONFIG_DISABLE_ES2015_BUILTIN + arg = ecma_op_to_object (arg); + if (ECMA_IS_VALUE_ERROR (arg)) + { + return arg; + } +#else /* CONFIG_DISABLE_ES2015_BUILTIN */ + return ecma_raise_type_error (ECMA_ERR_MSG ("Argument is not an object.")); +#endif /* !CONFIG_DISABLE_ES2015_BUILTIN */ + } + /* 2. */ + ecma_object_t *obj_p = ecma_get_object_from_value (arg); + ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p); + + if (prototype_p) + { + ret_value = ecma_make_object_value (prototype_p); + ecma_ref_object (prototype_p); } else { - /* 2. */ - ecma_object_t *obj_p = ecma_get_object_from_value (arg); - ecma_object_t *prototype_p = ecma_get_object_prototype (obj_p); + ret_value = ECMA_VALUE_NULL; + } - if (prototype_p) - { - ret_value = ecma_make_object_value (prototype_p); - ecma_ref_object (prototype_p); - } - else - { - ret_value = ECMA_VALUE_NULL; - } + if (!was_object) + { + ecma_free_value (arg); } return ret_value; diff --git a/tests/jerry/es2015/object-getprototypeof.js b/tests/jerry/es2015/object-getprototypeof.js new file mode 100644 index 0000000000..317697d9cb --- /dev/null +++ b/tests/jerry/es2015/object-getprototypeof.js @@ -0,0 +1,37 @@ +// 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. + +var a = true; +obj = Object.getPrototypeOf(a); +assert (obj == Boolean.prototype); + +a = 5; +obj = Object.getPrototypeOf(a); +assert (obj == Number.prototype); + +a = "string"; +obj = Object.getPrototypeOf(a); +assert (obj == String.prototype); + +a = [1,2,3]; +obj = Object.getPrototypeOf(a); +assert (obj == Array.prototype); + +try { + a = null; + obj = Object.getPrototypeOf(a); + assert(false); +} catch (e) { + assert(e instanceof TypeError); +} diff --git a/tests/jerry/object-getprototypeof.js b/tests/jerry/es5.1/object-getprototypeof.js similarity index 100% rename from tests/jerry/object-getprototypeof.js rename to tests/jerry/es5.1/object-getprototypeof.js diff --git a/tools/run-tests.py b/tools/run-tests.py index 1ee2e34f34..b2cf8aa6b0 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -264,6 +264,8 @@ def run_jerry_tests(options): if '--profile=es2015-subset' not in job.build_args: skip_list.append(r"es2015\/") + else: + skip_list.append(r"es5.1\/") if options.skip_list: skip_list.append(options.skip_list)