Added new target support for dataview object (#3764)
JerryScript-DCO-1.0-Signed-off-by: bence gabor kis kisbg@inf.u-szeged.hu
This commit is contained in:
@@ -3928,8 +3928,15 @@ jerry_create_dataview (const jerry_value_t array_buffer, /**< arraybuffer to cre
|
|||||||
ecma_make_uint32_value (byte_offset),
|
ecma_make_uint32_value (byte_offset),
|
||||||
ecma_make_uint32_value (byte_length)
|
ecma_make_uint32_value (byte_length)
|
||||||
};
|
};
|
||||||
|
ecma_object_t *old_new_target_p = JERRY_CONTEXT (current_new_target);
|
||||||
|
if (old_new_target_p == NULL)
|
||||||
|
{
|
||||||
|
JERRY_CONTEXT (current_new_target) = ecma_builtin_get (ECMA_BUILTIN_ID_DATAVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
return jerry_return (ecma_op_dataview_create (arguments_p, 3));
|
ecma_value_t dataview_value = ecma_op_dataview_create (arguments_p, 3);
|
||||||
|
JERRY_CONTEXT (current_new_target) = old_new_target_p;
|
||||||
|
return jerry_return (dataview_value);
|
||||||
#else /* !ENABLED (JERRY_BUILTIN_DATAVIEW) */
|
#else /* !ENABLED (JERRY_BUILTIN_DATAVIEW) */
|
||||||
JERRY_UNUSED (array_buffer);
|
JERRY_UNUSED (array_buffer);
|
||||||
JERRY_UNUSED (byte_offset);
|
JERRY_UNUSED (byte_offset);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "jcontext.h"
|
||||||
|
#include "ecma-function-object.h"
|
||||||
#include "ecma-arraybuffer-object.h"
|
#include "ecma-arraybuffer-object.h"
|
||||||
#include "ecma-builtins.h"
|
#include "ecma-builtins.h"
|
||||||
#include "ecma-exceptions.h"
|
#include "ecma-exceptions.h"
|
||||||
@@ -45,6 +47,7 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
|
|||||||
ecma_length_t arguments_list_len) /**< number of arguments */
|
ecma_length_t arguments_list_len) /**< number of arguments */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
|
||||||
|
JERRY_ASSERT (JERRY_CONTEXT (current_new_target));
|
||||||
|
|
||||||
ecma_value_t buffer = arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
|
ecma_value_t buffer = arguments_list_len > 0 ? arguments_list_p[0] : ECMA_VALUE_UNDEFINED;
|
||||||
|
|
||||||
@@ -127,7 +130,14 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 13. */
|
/* 13. */
|
||||||
ecma_object_t *object_p = ecma_create_object (ecma_builtin_get (ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE),
|
ecma_object_t *prototype_obj_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target),
|
||||||
|
ECMA_BUILTIN_ID_DATAVIEW_PROTOTYPE);
|
||||||
|
if (JERRY_UNLIKELY (prototype_obj_p == NULL))
|
||||||
|
{
|
||||||
|
return ECMA_VALUE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
|
||||||
sizeof (ecma_dataview_object_t),
|
sizeof (ecma_dataview_object_t),
|
||||||
ECMA_OBJECT_TYPE_CLASS);
|
ECMA_OBJECT_TYPE_CLASS);
|
||||||
|
|
||||||
@@ -137,6 +147,7 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
|
|||||||
dataview_obj_p->buffer_p = buffer_p;
|
dataview_obj_p->buffer_p = buffer_p;
|
||||||
dataview_obj_p->byte_offset = (uint32_t) offset;
|
dataview_obj_p->byte_offset = (uint32_t) offset;
|
||||||
|
|
||||||
|
ecma_deref_object (prototype_obj_p);
|
||||||
return ecma_make_object_value (object_p);
|
return ecma_make_object_value (object_p);
|
||||||
} /* ecma_op_dataview_create */
|
} /* ecma_op_dataview_create */
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* 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 buffer = new ArrayBuffer (16);
|
||||||
|
try {
|
||||||
|
Reflect.construct (DataView, [buffer], 4, 13);
|
||||||
|
assert (false);
|
||||||
|
} catch (e) {
|
||||||
|
assert (e instanceof TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Reflect.construct (DataView, [buffer], 1);
|
||||||
|
assert (false);
|
||||||
|
} catch (e) {
|
||||||
|
assert (e instanceof TypeError);
|
||||||
|
}
|
||||||
|
class MyDataView extends DataView {};
|
||||||
|
var d1 = new MyDataView(buffer);
|
||||||
|
|
||||||
|
assert(Object.getPrototypeOf(d1) == MyDataView.prototype)
|
||||||
Reference in New Issue
Block a user