Implement the ES2015 version of Object.getPrototypeOf and add a test file for it (#2256)
JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
This commit is contained in:
committed by
László Langó
parent
7b226f53e0
commit
8392eef8ad
@@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ecma-alloc.h"
|
#include "ecma-alloc.h"
|
||||||
#include "ecma-array-object.h"
|
|
||||||
#include "ecma-builtin-helpers.h"
|
#include "ecma-builtin-helpers.h"
|
||||||
#include "ecma-builtins.h"
|
#include "ecma-builtins.h"
|
||||||
#include "ecma-conversion.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);
|
JERRY_UNUSED (this_arg);
|
||||||
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
ecma_value_t ret_value = ECMA_VALUE_EMPTY;
|
||||||
|
bool was_object = ecma_is_value_object (arg);
|
||||||
|
|
||||||
/* 1. */
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
/* 2. */
|
ret_value = ECMA_VALUE_NULL;
|
||||||
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)
|
if (!was_object)
|
||||||
{
|
{
|
||||||
ret_value = ecma_make_object_value (prototype_p);
|
ecma_free_value (arg);
|
||||||
ecma_ref_object (prototype_p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret_value = ECMA_VALUE_NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -288,6 +288,8 @@ def run_jerry_tests(options):
|
|||||||
|
|
||||||
if '--profile=es2015-subset' not in job.build_args:
|
if '--profile=es2015-subset' not in job.build_args:
|
||||||
skip_list.append(r"es2015\/")
|
skip_list.append(r"es2015\/")
|
||||||
|
else:
|
||||||
|
skip_list.append(r"es5.1\/")
|
||||||
|
|
||||||
if options.skip_list:
|
if options.skip_list:
|
||||||
skip_list.append(options.skip_list)
|
skip_list.append(options.skip_list)
|
||||||
|
|||||||
Reference in New Issue
Block a user