1 /* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ecma-builtins.h"
17 #include "ecma-exceptions.h"
18 #include "ecma-gc.h"
19 #include "ecma-globals.h"
20 #include "ecma-helpers.h"
21 #include "ecma-arraybuffer-object.h"
22 #include "ecma-dataview-object.h"
23 #include "ecma-try-catch-macro.h"
24 #include "ecma-typedarray-object.h"
25 #include "jrt.h"
26
27 #if ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY)
28
29 #define ECMA_BUILTINS_INTERNAL
30 #include "ecma-builtins-internal.h"
31
32 #define BUILTIN_INC_HEADER_NAME "ecma-builtin-arraybuffer.inc.h"
33 #define BUILTIN_UNDERSCORED_ID arraybuffer
34 #include "ecma-builtin-internal-routines-template.inc.h"
35
36 /** \addtogroup ecma ECMA
37 * @{
38 *
39 * \addtogroup ecmabuiltins
40 * @{
41 *
42 * \addtogroup arraybuffer ECMA ArrayBuffer object built-in
43 * @{
44 */
45
46 /**
47 * The ArrayBuffer object's 'isView' routine
48 *
49 * See also:
50 * ES2015 24.1.3.1
51 *
52 * @return ecma value
53 * Returned value must be freed with ecma_free_value.
54 */
55 static ecma_value_t
ecma_builtin_arraybuffer_object_is_view(ecma_value_t this_arg,ecma_value_t arg)56 ecma_builtin_arraybuffer_object_is_view (ecma_value_t this_arg, /**< 'this' argument */
57 ecma_value_t arg) /**< argument 1 */
58 {
59 JERRY_UNUSED (this_arg);
60 #if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW)
61 return ecma_make_boolean_value (ecma_is_typedarray (arg) || ecma_is_dataview (arg));
62 #else
63 JERRY_UNUSED (arg);
64 return ECMA_VALUE_FALSE;
65 #endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW */
66 } /* ecma_builtin_arraybuffer_object_is_view */
67
68 /**
69 * Handle calling [[Call]] of built-in ArrayBuffer object
70 *
71 * ES2015 24.1.2 ArrayBuffer is not intended to be called as
72 * a function and will throw an exception when called in
73 * that manner.
74 *
75 * @return ecma value
76 */
77 ecma_value_t
ecma_builtin_arraybuffer_dispatch_call(const ecma_value_t * arguments_list_p,ecma_length_t arguments_list_len)78 ecma_builtin_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
79 ecma_length_t arguments_list_len) /**< number of arguments */
80 {
81 JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
82
83 return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor ArrayBuffer requires 'new'"));
84 } /* ecma_builtin_arraybuffer_dispatch_call */
85
86 /**
87 * Handle calling [[Construct]] of built-in ArrayBuffer object
88 *
89 * @return ecma value
90 */
91 ecma_value_t
ecma_builtin_arraybuffer_dispatch_construct(const ecma_value_t * arguments_list_p,ecma_length_t arguments_list_len)92 ecma_builtin_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
93 ecma_length_t arguments_list_len) /**< number of arguments */
94 {
95 JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
96
97 return ecma_op_create_arraybuffer_object (arguments_list_p, arguments_list_len);
98 } /* ecma_builtin_arraybuffer_dispatch_construct */
99
100 /**
101 * 24.1.3.3 get ArrayBuffer [ @@species ] accessor
102 *
103 * @return ecma_value
104 * returned value must be freed with ecma_free_value
105 */
106 ecma_value_t
ecma_builtin_arraybuffer_species_get(ecma_value_t this_value)107 ecma_builtin_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */
108 {
109 return ecma_copy_value (this_value);
110 } /* ecma_builtin_arraybuffer_species_get */
111
112 /**
113 * @}
114 * @}
115 * @}
116 */
117
118 #endif /* ENABLED (JERRY_ES2015_BUILTIN_TYPEDARRAY) */
119