diff --git a/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.c b/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.c index 5d60942af..f36140286 100644 --- a/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.c +++ b/jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-helpers.c @@ -21,6 +21,8 @@ #include "ecma-gc.h" #include "ecma-objects.h" #include "ecma-typedarray-object.h" +#include "ecma-function-object.h" +#include "jcontext.h" #define ECMA_BUILTINS_INTERNAL #include "ecma-builtins-internal.h" @@ -37,14 +39,25 @@ ecma_typedarray_helper_dispatch_construct (const ecma_value_t *arguments_list_p, ecma_typedarray_type_t typedarray_id) /**< id of the typedarray */ { JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); + ecma_builtin_id_t proto_id = ecma_typedarray_helper_get_prototype_id (typedarray_id); + ecma_object_t *prototype_obj_p = ecma_builtin_get (proto_id); + + if (JERRY_CONTEXT (current_new_target)) + { + prototype_obj_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target), proto_id); + } - ecma_object_t *prototype_obj_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (typedarray_id)); ecma_value_t val = ecma_op_create_typedarray (arguments_list_p, arguments_list_len, prototype_obj_p, ecma_typedarray_helper_get_shift_size (typedarray_id), typedarray_id); + if (JERRY_CONTEXT (current_new_target)) + { + ecma_deref_object (prototype_obj_p); + } + return val; } /* ecma_typedarray_helper_dispatch_construct */ diff --git a/jerry-core/ecma/operations/ecma-arraybuffer-object.c b/jerry-core/ecma/operations/ecma-arraybuffer-object.c index 04a47d7ad..7f8df92c2 100644 --- a/jerry-core/ecma/operations/ecma-arraybuffer-object.c +++ b/jerry-core/ecma/operations/ecma-arraybuffer-object.c @@ -22,6 +22,8 @@ #include "ecma-globals.h" #include "ecma-helpers.h" #include "jmem.h" +#include "jcontext.h" +#include "ecma-function-object.h" #if ENABLED (JERRY_BUILTIN_TYPEDARRAY) @@ -141,7 +143,19 @@ ecma_op_create_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< li uint32_t length_uint32 = ecma_number_to_uint32 (length_num); - return ecma_make_object_value (ecma_arraybuffer_new_object (length_uint32)); + ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target), + ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE); + + if (proto_p == NULL) + { + return ECMA_VALUE_ERROR; + } + + ecma_object_t *array_buffer = ecma_arraybuffer_new_object (length_uint32); + ECMA_SET_NON_NULL_POINTER (array_buffer->u2.prototype_cp, proto_p); + ecma_deref_object (proto_p); + + return ecma_make_object_value (array_buffer); } /* ecma_op_create_arraybuffer_object */ /** diff --git a/tests/jerry/es.next/new-target-for-typedarray-and-arraybuffer.js b/tests/jerry/es.next/new-target-for-typedarray-and-arraybuffer.js new file mode 100644 index 000000000..183eed6af --- /dev/null +++ b/tests/jerry/es.next/new-target-for-typedarray-and-arraybuffer.js @@ -0,0 +1,25 @@ +/* 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. + */ + +class MyInt32Array extends Int32Array {}; +var t1= new MyInt32Array([1,2]); + +assert(Object.getPrototypeOf(t1) == MyInt32Array.prototype) + + +class MyArrayBuffer extends ArrayBuffer {}; +var t2= new MyArrayBuffer(8); + +assert(Object.getPrototypeOf(t2) == MyArrayBuffer.prototype) diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index a18ff17c4..744f1fdb5 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -3,7 +3,6 @@ - @@ -304,30 +303,21 @@ - - - - - - - - - @@ -9528,7 +9518,6 @@ - @@ -9662,17 +9651,7 @@ - - - - - - - - - -