@@ -296,6 +296,26 @@ typedef jerry_value_t (*jerry_vm_exec_stop_callback_t) (void *user_p);
296
296
- [jerry_set_vm_exec_stop_callback](#jerry_set_vm_exec_stop_callback)
297
297
298
298
299
+ ## jerry_typedarray_class_t
300
+
301
+ Enum which describes the TypedArray types.
302
+ Possible values:
303
+
304
+ - JERRY_TYPEDARRAY_UINT8 - represents the Uint8Array TypedArray
305
+ - JERRY_TYPEDARRAY_UINT8CLAMPED - represents the Uint8ClampedArray TypedArray
306
+ - JERRY_TYPEDARRAY_INT8 - represents the Int8Array TypedArray
307
+ - JERRY_TYPEDARRAY_UINT16 - represents the Uint16Array TypedArray
308
+ - JERRY_TYPEDARRAY_INT16 - represents the Int16Array TypedArray
309
+ - JERRY_TYPEDARRAY_UINT32 - represents the Uint32Array TypedArray
310
+ - JERRY_TYPEDARRAY_INT32 - represents the Int32Array TypedArray
311
+ - JERRY_TYPEDARRAY_FLOAT32 - represents the Float32Array TypedArray
312
+ - JERRY_TYPEDARRAY_FLOAT64 - represents the Float64Array TypedArray
313
+ - JERRY_TYPEDARRAY_UNKNOWN - represents an invalid TypedArray
314
+
315
+ API functions can return the `JERRY_TYPEDARRAY_UNKNOWN` value if the
316
+ TypedArray support is not in the engine.
317
+
318
+
299
319
# General engine functions
300
320
301
321
## jerry_init
@@ -1346,6 +1366,45 @@ jerry_value_is_string (const jerry_value_t value)
1346
1366
- [jerry_release_value](#jerry_release_value)
1347
1367
1348
1368
1369
+ ## jerry_value_is_typedarray
1370
+
1371
+ **Summary**
1372
+
1373
+ Checks whether the given `jerry_value_t` is a TypedArray object or not.
1374
+
1375
+ **Prototype**
1376
+
1377
+ ```c
1378
+ bool
1379
+ jerry_value_is_typedbuffer (const jerry_value_t value)
1380
+ ```
1381
+
1382
+ - `value` - object to check
1383
+ - return value
1384
+ - true, if the given `jerry_value_t` is a TypedArray object.
1385
+ - false, otherwise
1386
+
1387
+ **Example**
1388
+
1389
+ ```c
1390
+ {
1391
+ jerry_value_t value;
1392
+ ... // create or acquire value
1393
+
1394
+ if (jerry_value_is_typedarray (value))
1395
+ {
1396
+ ...
1397
+ }
1398
+
1399
+ jerry_release_value (value);
1400
+ }
1401
+ ```
1402
+
1403
+ **See also**
1404
+
1405
+ - [jerry_create_typedarray](#jerry_create_typedarray)
1406
+
1407
+
1349
1408
## jerry_value_is_undefined
1350
1409
1351
1410
**Summary**
@@ -2985,6 +3044,151 @@ jerry_create_string_sz (const jerry_char_t *str_p,
2985
3044
- [jerry_create_string_from_utf8](#jerry_create_string_from_utf8)
2986
3045
2987
3046
3047
+ ## jerry_create_typedarray
3048
+
3049
+ **Summary**
3050
+
3051
+ Create a jerry_value_t representing an TypedArray object.
3052
+
3053
+ For the new object the type of the TypedArray (see: [jerry_typedarray_class_t](#jerry_typedarray_class_t))
3054
+ and element count can be specified.
3055
+
3056
+ **Prototype**
3057
+
3058
+ ```c
3059
+ jerry_value_t
3060
+ jerry_create_typedarray (jerry_typedarray_class_t class_name, jerry_length_t length);
3061
+ ```
3062
+
3063
+ - `class_name` - type of TypedArray to create
3064
+ - `length` - length of the new TypedArray
3065
+ - return value - the new TypedArray as a `jerry_value_t`
3066
+
3067
+ **Example**
3068
+
3069
+ ```c
3070
+ {
3071
+ jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_UINT16, 15);
3072
+
3073
+ ... // use the TypedArray
3074
+
3075
+ jerry_release_value (array);
3076
+ }
3077
+ ```
3078
+
3079
+ **See also**
3080
+
3081
+ - [jerry_typedarray_class_t](#jerry_typedarray_class_t)
3082
+ - [jerry_value_is_typedarray](#jerry_value_is_typedarray)
3083
+ - [jerry_release_value](#jerry_release_value)
3084
+
3085
+
3086
+ ## jerry_create_typedarray_with_arraybuffer
3087
+
3088
+ **Summary**
3089
+
3090
+ Create a jerry_value_t representing an TypedArray object using
3091
+ an already existing ArrayBuffer object.
3092
+
3093
+ For the new object the type of the TypedArray (see: [jerry_typedarray_class_t](#jerry_typedarray_class_t))
3094
+ and element count can be specified.
3095
+
3096
+ The developer must ensure that the ArrayBuffer has the correct length for the given
3097
+ type of TypedArray otherwise an error is generated.
3098
+
3099
+ The JavaScript equivalent of this function is: `new %TypedArray%(arraybuffer)` where `%TypedArray%` is
3100
+ one of the allowed TypedArray functions.
3101
+
3102
+ **Prototype**
3103
+
3104
+ ```c
3105
+ jerry_value_t
3106
+ jerry_create_typedarray_with_arraybuffer (jerry_typedarray_class_t class_name,
3107
+ const jerry_value_t arraybuffer);
3108
+ ```
3109
+
3110
+ - `class_name` - type of TypedArray to create
3111
+ - `arraybuffer` - the ArrayBuffer to use for the new TypedArray
3112
+ - return value
3113
+ - the new TypedArray as a `jerry_value_t`
3114
+ - Error if the ArrayBuffer does not have enough space for the given type of TypedArray
3115
+
3116
+ **Example**
3117
+
3118
+ ```c
3119
+ {
3120
+ jerry_value_t buffer = jerry_create_array_buffer (12 * 2);
3121
+ jerry_value_t array = jerry_create_typedarray_with_arraybuffer (JERRY_TYPEDARRAY_UINT16, buffer);
3122
+ jerry_release_value (buffer);
3123
+
3124
+ ... // use the TypedArray
3125
+
3126
+ jerry_release_value (array);
3127
+ }
3128
+ ```
3129
+
3130
+ **See also**
3131
+
3132
+ - [jerry_typedarray_class_t](#jerry_typedarray_class_t)
3133
+ - [jerry_value_is_typedarray](#jerry_value_is_typedarray)
3134
+ - [jerry_release_value](#jerry_release_value)
3135
+
3136
+
3137
+ ## jerry_create_typedarray_with_arraybuffer_sz
3138
+
3139
+ **Summary**
3140
+
3141
+ Create a jerry_value_t representing an TypedArray object using
3142
+ an already existing ArrayBuffer object and by specifying the byteOffset, and length properties.
3143
+
3144
+ For the new object the type of the TypedArray (see: [jerry_typedarray_class_t](#jerry_typedarray_class_t))
3145
+ and element count can be specified.
3146
+
3147
+ The developer must ensure that the ArrayBuffer has the correct length for the given
3148
+ type of TypedArray otherwise an error is generated.
3149
+
3150
+ The JavaScript equivalent of this function is: `new %TypedArray%(arraybuffer, byteOffset, length)` where `%TypedArray%` is
3151
+ one of the allowed TypedArray functions.
3152
+
3153
+ **Prototype**
3154
+
3155
+ ```c
3156
+ jerry_value_t
3157
+ jerry_create_typedarray_with_arraybuffer_sz (jerry_typedarray_class_t class_name,
3158
+ const jerry_value_t arraybuffer,
3159
+ jerry_length_t byte_offset,
3160
+ jerry_length_t length);
3161
+ ```
3162
+
3163
+ - `class_name` - type of TypedArray to create
3164
+ - `arraybuffer` - the ArrayBuffer to use for the new TypedArray
3165
+ - `byte_offset` - start offset to use for the ArrayBuffer
3166
+ - `length` - number of elements to used from the ArrayBuffer (this is not the same as the byteLength)
3167
+ - return value
3168
+ - the new TypedArray as a `jerry_value_t`
3169
+ - Error if the ArrayBuffer does not have enough space for the given type of TypedArray
3170
+
3171
+ **Example**
3172
+
3173
+ ```c
3174
+ {
3175
+ jerry_value_t buffer = jerry_create_array_buffer (12 * 2);
3176
+ jerry_value_t array = jerry_create_typedarray_with_arraybuffer (JERRY_TYPEDARRAY_UINT16, buffer, 4, 10);
3177
+ jerry_release_value (buffer);
3178
+
3179
+ ... // use the TypedArray
3180
+
3181
+ jerry_release_value (array);
3182
+ }
3183
+ ```
3184
+
3185
+ **See also**
3186
+
3187
+ - [jerry_typedarray_class_t](#jerry_typedarray_class_t)
3188
+ - [jerry_value_is_typedarray](#jerry_value_is_typedarray)
3189
+ - [jerry_release_value](#jerry_release_value)
3190
+
3191
+
2988
3192
## jerry_create_undefined
2989
3193
2990
3194
**Summary**
@@ -4921,3 +5125,133 @@ jerry_arraybuffer_write (const jerry_value_t value,
4921
5125
- [jerry_create_arraybuffer](#jerry_create_arraybuffer)
4922
5126
- [jerry_arraybuffer_write](#jerry_arraybuffer_write)
4923
5127
- [jerry_get_arraybuffer_byte_length](#jerry_get_arraybuffer_byte_length)
5128
+
5129
+
5130
+ ## jerry_get_typedarray_type
5131
+
5132
+ **Summary**
5133
+
5134
+ Get the type of the TypedArray.
5135
+
5136
+ The returned type is one of the [jerry_typedarray_class_t](#jerry_typedarray_class_t)
5137
+ enum value.
5138
+
5139
+ **Prototype**
5140
+
5141
+ ```c
5142
+ jerry_typedarray_class_t
5143
+ jerry_get_typedarray_type (jerry_value_t value);
5144
+ ```
5145
+
5146
+ - `value` - TypedArray object to query for type.
5147
+ - return
5148
+ - the type of the TypedArray
5149
+ - JERRY_TYPEDARRAY_UNKNOWN if the object was not a TypedArray
5150
+
5151
+ **Example**
5152
+
5153
+ ```c
5154
+ {
5155
+ jerry_typedarray_class_t expected_klass = JERRY_TYPEDARRAY_UINT32;
5156
+ jerry_value_t typedarray = jerry_create_typedarray (expected_klass, 25);
5157
+
5158
+ jerry_typedarray_class_t klass = jerry_get_typedarray_type (typedarray);
5159
+
5160
+ // klass is now JERRY_TYPEDARRAY_UINT32
5161
+
5162
+ jerry_release_value (typedarray);
5163
+ }
5164
+ ```
5165
+
5166
+ **See also**
5167
+
5168
+ - [jerry_create_typedarray](#jerry_create_typedarray)
5169
+
5170
+
5171
+ ## jerry_get_typedarray_length
5172
+
5173
+ **Summary**
5174
+
5175
+ Get the element count of the TypedArray as specified during creation.
5176
+
5177
+ This is not the same as the byteLength property of a TypedArray object.
5178
+
5179
+ **Prototype**
5180
+
5181
+ ```c
5182
+ jerry_length_t
5183
+ jerry_get_typedarray_length (jerry_value_t value);
5184
+ ```
5185
+
5186
+ - `value` - TypedArray object to query
5187
+ - return
5188
+ - length (element count) of the TypedArray object
5189
+ - 0 if the object is not a TypedArray
5190
+
5191
+ **Example**
5192
+
5193
+ ```c
5194
+ {
5195
+ jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_INT32, 21);
5196
+
5197
+ jerry_length_t element_count = jerry_get_typedarray_length (array);
5198
+
5199
+ // element_count is now 21.
5200
+
5201
+ jerry_release_value (array);
5202
+ }
5203
+ ```
5204
+
5205
+ **See also**
5206
+
5207
+ - [jerry_create_typedarray](#jerry_create_typedarray)
5208
+
5209
+
5210
+ ## jerry_get_typedarray_buffer
5211
+
5212
+ **Summary**
5213
+
5214
+ Get the ArrayBuffer object used by a TypedArray object.
5215
+ Additionally returns the byteLength and byteOffset properties
5216
+ of the TypedArray object.
5217
+
5218
+ For the returned ArrayBuffer the [jerry_release_value](#jerry_release_value)
5219
+ must be called.
5220
+
5221
+ **Prototype**
5222
+
5223
+ ```c
5224
+ jerry_value_t jerry_get_typedarray_buffer (jerry_value_t value,
5225
+ jerry_length_t *byteOffset,
5226
+ jerry_length_t *byteLength);
5227
+ ```
5228
+
5229
+ - `value` - TypedArray to get the ArrayBuffer from
5230
+ - `byteOffset` - start offset of the ArrayBuffer for the TypedArray
5231
+ - `byteLength` - number of bytes used from the ArrayBuffer for the TypedArray
5232
+ - return
5233
+ - TypedArray object's underlying ArrayBuffer object
5234
+ - TypeError if the `value` is not a TypedArray object
5235
+
5236
+ **Example**
5237
+
5238
+ ```c
5239
+ {
5240
+ jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_INT16, 11);
5241
+
5242
+ jerry_length_t byteLength = 0;
5243
+ jerry_length_t byteOffset = 0;
5244
+ jerry_value_t buffer = jerry_get_typedarray_buffer (array, &byteOffset, &byteLength);
5245
+
5246
+ // buffer is an ArrayBuffer object and ArrayBuffer operations can be performed on it
5247
+ // byteLength is 11 * 2 (2 as the TypedArray stores Int16 that is 2 byte elements)
5248
+ // byteOffset is 0
5249
+
5250
+ jerry_release_value (buffer);
5251
+ jerry_release_value (array);
5252
+ }
5253
+ ```
5254
+
5255
+ **See also**
5256
+
5257
+ - [jerry_create_typedarray](#jerry_create_typedarray)
0 commit comments