mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Implement ArrayBuffer.isView function (#3403)
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs r.takacs2@partner.samsung.com
This commit is contained in:
parent
59eb0787ba
commit
67d677a1bc
@ -3743,15 +3743,7 @@ jerry_value_is_dataview (const jerry_value_t value) /**< value to check if it is
|
||||
jerry_assert_api_available ();
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_dataview_object_t *dataview_object_p = (ecma_dataview_object_t *) ecma_get_object_from_value (value);
|
||||
|
||||
return (ecma_get_object_type (&dataview_object_p->header.object) == ECMA_OBJECT_TYPE_CLASS
|
||||
&& dataview_object_p->header.u.class_prop.class_id == LIT_MAGIC_STRING_DATAVIEW_UL);
|
||||
return ecma_is_dataview (value);
|
||||
#else /* !ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) */
|
||||
JERRY_UNUSED (value);
|
||||
return false;
|
||||
|
||||
@ -19,7 +19,9 @@
|
||||
#include "ecma-globals.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "ecma-arraybuffer-object.h"
|
||||
#include "ecma-dataview-object.h"
|
||||
#include "ecma-try-catch-macro.h"
|
||||
#include "ecma-typedarray-object.h"
|
||||
#include "jrt.h"
|
||||
|
||||
#if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
|
||||
@ -55,11 +57,8 @@ ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argu
|
||||
ecma_value_t arg) /**< argument 1 */
|
||||
{
|
||||
JERRY_UNUSED (this_arg);
|
||||
JERRY_UNUSED (arg);
|
||||
|
||||
/* TODO: if arg has [[ViewArrayBuffer]], return true */
|
||||
|
||||
return ECMA_VALUE_FALSE;
|
||||
return ecma_make_boolean_value (ecma_is_typedarray (arg) || ecma_is_dataview (arg));
|
||||
} /* ecma_builtin_arraybuffer_object_is_view */
|
||||
|
||||
/**
|
||||
|
||||
@ -306,6 +306,26 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
|
||||
return ECMA_VALUE_UNDEFINED;
|
||||
} /* ecma_op_dataview_get_set_view_value */
|
||||
|
||||
/**
|
||||
* Check if the value is dataview
|
||||
*
|
||||
* @return true - if value is a DataView object
|
||||
* false - otherwise
|
||||
*/
|
||||
bool
|
||||
ecma_is_dataview (ecma_value_t value) /**< the target need to be checked */
|
||||
{
|
||||
if (!ecma_is_value_object (value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ecma_dataview_object_t *dataview_object_p = (ecma_dataview_object_t *) ecma_get_object_from_value (value);
|
||||
|
||||
return (ecma_get_object_type (&dataview_object_p->header.object) == ECMA_OBJECT_TYPE_CLASS
|
||||
&& dataview_object_p->header.u.class_prop.class_id == LIT_MAGIC_STRING_DATAVIEW_UL);
|
||||
} /* ecma_is_dataview */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
|
||||
@ -32,6 +32,7 @@ ecma_dataview_object_t *ecma_op_dataview_get_object (ecma_value_t this_arg);
|
||||
ecma_value_t ecma_op_dataview_get_set_view_value (ecma_value_t view, ecma_value_t request_index,
|
||||
ecma_value_t little_endian, ecma_value_t value_to_set,
|
||||
ecma_typedarray_type_t id);
|
||||
bool ecma_is_dataview (ecma_value_t value);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
37
tests/jerry/es2015/arraybuffer-isview.js
Normal file
37
tests/jerry/es2015/arraybuffer-isview.js
Normal file
@ -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.
|
||||
*/
|
||||
|
||||
assert(ArrayBuffer.isView() === false);
|
||||
assert(ArrayBuffer.isView([]) === false);
|
||||
assert(ArrayBuffer.isView({}) === false);
|
||||
assert(ArrayBuffer.isView(null) === false);
|
||||
assert(ArrayBuffer.isView(undefined) === false);
|
||||
assert(ArrayBuffer.isView(new ArrayBuffer(10)) === false);
|
||||
|
||||
assert(ArrayBuffer.isView(new Int8Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Uint8Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Uint8ClampedArray()) === true);
|
||||
assert(ArrayBuffer.isView(new Int16Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Uint16Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Int32Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Uint32Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Float32Array()) === true);
|
||||
assert(ArrayBuffer.isView(new Float64Array()) === true);
|
||||
|
||||
assert(ArrayBuffer.isView(new Int8Array(10).subarray(0, 3)) === true);
|
||||
|
||||
var buffer = new ArrayBuffer(2);
|
||||
var dv = new DataView(buffer);
|
||||
assert(ArrayBuffer.isView(dv) === true);
|
||||
Loading…
x
Reference in New Issue
Block a user