diff --git a/docs/02.API-REFERENCE.md b/docs/02.API-REFERENCE.md
index 854c72df8..eccb74b8e 100644
--- a/docs/02.API-REFERENCE.md
+++ b/docs/02.API-REFERENCE.md
@@ -52,6 +52,7 @@ Enum that contains JerryScript **object** value types:
- JERRY_OBJECT_TYPE_CONTAINER - Container object (see [jerry_get_container_type](#jerry_get_container_type))
- JERRY_OBJECT_TYPE_ERROR - Error object
- JERRY_OBJECT_TYPE_ARRAYBUFFER - Array buffer object
+ - JERRY_OBJECT_TYPE_SHARED_ARRAYBUFFER - Shared Array buffer object
- JERRY_OBJECT_TYPE_ARGUMENTS - Arguments object
- JERRY_OBJECT_TYPE_BOOLEAN - Boolean object
@@ -2130,6 +2131,53 @@ jerry_value_is_arraybuffer (const jerry_value_t value)
- [jerry_create_arraybuffer](#jerry_create_arraybuffer)
- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external)
+## jerry_value_is_shared_arraybuffer
+
+**Summary**
+
+Returns whether the given `jerry_value_t` is a SharedArrayBuffer object.
+
+*Notes*:
+- This API depends on a build option (`JERRY_BUILTIN_TYPEDARRAY`) and can be checked
+ in runtime with the `JERRY_FEATURE_TYPEDARRAY` feature enum value,
+ see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
+- The es.next profile enables this by default.
+
+**Prototype**
+
+```c
+bool
+jerry_value_is_shared_arraybuffer (const jerry_value_t value);
+```
+
+- `value` - api value to check.
+- return value
+ - true, if the given `jerry_value_t` is a SharedArrayBuffer object.
+ - false, otherwise
+
+*New in version [[NEXT_RELEASE]]*.
+
+**Example**
+
+```c
+{
+ jerry_value_t value;
+ ... // create or acquire value
+
+ if (jerry_value_is_shared_arraybuffer (value))
+ {
+ ...
+ }
+
+ jerry_release_value (value);
+}
+```
+
+**See also**
+
+- [jerry_create_shared_arraybuffer](#jerry_create_shared_arraybuffer)
+- [jerry_create_shared_arraybuffer_external](#jerry_create_shared_arraybuffer_external)
+
## jerry_value_is_boolean
@@ -6193,6 +6241,108 @@ jerry_create_arraybuffer_external (const jerry_length_t size
- [jerry_object_native_free_callback_t](#jerry_object_native_free_callback_t)
+## jerry_create_shared_arraybuffer
+
+**Summary**
+
+Create a jerry_value_t representing a SharedArrayBuffer object.
+
+*Note*:
+- This API depends on the es.next profile.
+- Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
+**Prototype**
+
+```c
+jerry_value_t
+jerry_create_shared_arraybuffer (jerry_length_t size);
+```
+
+- `size` - size of the SharedArrayBuffer to create **in bytes**
+- return value - the new SharedArrayBuffer as a `jerry_value_t`
+
+*New in version [[NEXT_RELEASE]]*.
+
+**Example**
+
+```c
+{
+ jerry_value_t buffer_value = jerry_create_shared_arraybuffer (15);
+
+ ... // use the SharedArrayBuffer
+
+ jerry_release_value (buffer_value);
+}
+```
+
+**See also**
+
+- [jerry_arraybuffer_read](#jerry_arraybuffer_read)
+- [jerry_arraybuffer_write](#jerry_arraybuffer_write)
+- [jerry_value_is_shared_arraybuffer](#jerry_value_is_shared_arraybuffer)
+- [jerry_release_value](#jerry_release_value)
+
+
+## jerry_create_shared_arraybuffer_external
+
+**Summary**
+
+Creates a jerry_value_t representing an SharedArrayBuffer object with
+user specified back-buffer.
+
+User must pass a buffer pointer which is at least `size` big.
+After the object is not needed the GC will call the `free_cb`
+so the user can release the buffer which was provided.
+
+*Note*:
+- This API depends on the es.next profile.
+- Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
+**Prototype**
+
+```c
+jerry_value_t
+jerry_create_shared_arraybuffer_external (const jerry_length_t size
+ uint8_t *buffer_p,
+ jerry_value_free_callback_t free_cb);
+```
+
+- `size` - size of the buffer to use **in bytes** (should not be 0)
+- `buffer_p` - the buffer used for the Shared Array Buffer object (should not be a null pointer)
+- `free_cb` - the callback function called when the object is released
+- return value
+ - the new SharedArrayBuffer as a `jerry_value_t`
+ - if the `size` is zero or `buffer_p` is a null pointer this will return an empty SharedArrayBuffer.
+
+*New in version [[NEXT_RELEASE]]*.
+
+*Changed in version [[NEXT_RELEASE]]*: type of `free_cb` has been changed.
+
+**Example**
+
+```c
+{
+ uint8_t buffer_p[15];
+ jerry_value_t buffer_value = jerry_create_shared_arraybuffer_external (15, buffer_p, NULL);
+
+ ... // use the shared array buffer
+
+ jerry_release_value (buffer_value);
+}
+```
+
+**See also**
+
+- [jerry_get_arraybuffer_pointer](#jerry_get_arraybuffer_pointer)
+- [jerry_arraybuffer_read](#jerry_arraybuffer_read)
+- [jerry_arraybuffer_write](#jerry_arraybuffer_write)
+- [jerry_value_is_shared_arraybuffer](#jerry_value_is_shared_arraybuffer)
+- [jerry_release_value](#jerry_release_value)
+- [jerry_object_native_free_callback_t](#jerry_object_native_free_callback_t)
+
+
## jerry_create_boolean
**Summary**
@@ -11414,7 +11564,7 @@ These APIs all depend on the es.next profile.
**Summary**
-Get the byte length property of the ArrayBuffer. This is the
+Get the byte length property of the ArrayBuffer or SharedArrayBuffer. This is the
same value which was passed to the ArrayBuffer constructor call.
**Prototype**
@@ -11451,7 +11601,7 @@ jerry_get_arraybuffer_byte_length (const jerry_value_t value);
**Summary**
-Copy the portion of the ArrayBuffer into a user provided buffer.
+Copy the portion of the ArrayBuffer or SharedArrayBuffer into a user provided buffer.
The start offset of the read operation can be specified.
The number bytes to be read can be specified via the `buf_size`
@@ -11515,7 +11665,7 @@ jerry_arraybuffer_read (const jerry_value_t value,
**Summary**
-Copy the contents of a buffer into the ArrayBuffer.
+Copy the contents of a buffer into the ArrayBuffer or SharedArrayBuffer.
The start offset of the write operation can be specified.
The number bytes to be written can be specified via the `buf_size`
diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt
index a818c0571..b988da780 100644
--- a/jerry-core/CMakeLists.txt
+++ b/jerry-core/CMakeLists.txt
@@ -210,6 +210,8 @@ set(SOURCE_CORE_FILES
ecma/builtin-objects/ecma-builtin-set-iterator-prototype.c
ecma/builtin-objects/ecma-builtin-set-prototype.c
ecma/builtin-objects/ecma-builtin-set.c
+ ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.c
+ ecma/builtin-objects/ecma-builtin-shared-arraybuffer.c
ecma/builtin-objects/ecma-builtin-string-iterator-prototype.c
ecma/builtin-objects/ecma-builtin-string-prototype.c
ecma/builtin-objects/ecma-builtin-string.c
@@ -281,6 +283,7 @@ set(SOURCE_CORE_FILES
ecma/operations/ecma-proxy-object.c
ecma/operations/ecma-reference.c
ecma/operations/ecma-regexp-object.c
+ ecma/operations/ecma-shared-arraybuffer-object.c
ecma/operations/ecma-string-object.c
ecma/operations/ecma-symbol-object.c
ecma/operations/ecma-typedarray-object.c
@@ -405,6 +408,8 @@ if(ENABLE_AMALGAM)
ecma/builtin-objects/ecma-builtin-set-iterator-prototype.inc.h
ecma/builtin-objects/ecma-builtin-set-prototype.inc.h
ecma/builtin-objects/ecma-builtin-set.inc.h
+ ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h
+ ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h
ecma/builtin-objects/ecma-builtin-string-iterator-prototype.inc.h
ecma/builtin-objects/ecma-builtin-string-prototype.inc.h
ecma/builtin-objects/ecma-builtin-string.inc.h
@@ -452,6 +457,7 @@ if(ENABLE_AMALGAM)
ecma/operations/ecma-proxy-object.h
ecma/operations/ecma-reference.h
ecma/operations/ecma-regexp-object.h
+ ecma/operations/ecma-shared-arraybuffer-object.h
ecma/operations/ecma-string-object.h
ecma/operations/ecma-symbol-object.h
ecma/operations/ecma-typedarray-object.h
diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c
index 4f6e7ec3d..2422267a6 100644
--- a/jerry-core/api/jerry.c
+++ b/jerry-core/api/jerry.c
@@ -41,6 +41,7 @@
#include "ecma-regexp-object.h"
#include "ecma-promise-object.h"
#include "ecma-proxy-object.h"
+#include "ecma-shared-arraybuffer-object.h"
#include "ecma-symbol-object.h"
#include "ecma-typedarray-object.h"
#include "jcontext.h"
@@ -1545,6 +1546,7 @@ static const uint8_t jerry_class_object_type[] =
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_TYPEDARRAY
JERRY_OBJECT_TYPE_ARRAYBUFFER, /**< type of ECMA_OBJECT_CLASS_ARRAY_BUFFER */
+ JERRY_OBJECT_TYPE_SHARED_ARRAY_BUFFER, /**< type of ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER */
#endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_BUILTIN_BIGINT
JERRY_OBJECT_TYPE_BIGINT, /**< type of ECMA_OBJECT_CLASS_BIGINT */
@@ -5622,15 +5624,96 @@ jerry_create_arraybuffer_external (const jerry_length_t size, /**< size of the b
} /* jerry_create_arraybuffer_external */
/**
- * Copy bytes into the ArrayBuffer from a buffer.
+ * Check if the given value is a SharedArrayBuffer object.
+ *
+ * @return true - if it is a SharedArrayBuffer object
+ * false - otherwise
+ */
+bool
+jerry_value_is_shared_arraybuffer (const jerry_value_t value) /**< value to check if it is a SharedArrayBuffer */
+{
+ jerry_assert_api_available ();
+
+#if JERRY_BUILTIN_TYPEDARRAY
+ return ecma_is_shared_arraybuffer (value);
+#else /* !JERRY_BUILTIN_TYPEDARRAY */
+ JERRY_UNUSED (value);
+ return false;
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
+} /* jerry_value_is_shared_arraybuffer */
+
+/**
+ * Creates a SharedArrayBuffer object with the given length (size).
+ *
+ * Notes:
+ * * the length is specified in bytes.
+ * * returned value must be freed with jerry_release_value, when it is no longer needed.
+ * * if the typed arrays are disabled this will return a TypeError.
+ *
+ * @return value of the constructed SharedArrayBuffer object
+ */
+jerry_value_t
+jerry_create_shared_arraybuffer (const jerry_length_t size) /**< size of the SharedArrayBuffer to create */
+{
+ jerry_assert_api_available ();
+
+#if JERRY_BUILTIN_TYPEDARRAY
+ return jerry_return (ecma_make_object_value (ecma_shared_arraybuffer_new_object (size)));
+#else /* !JERRY_BUILTIN_TYPEDARRAY */
+ JERRY_UNUSED (size);
+ return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)));
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
+} /* jerry_create_shared_arraybuffer */
+
+/**
+ * Creates a SharedArrayBuffer object with user specified buffer.
+ *
+ * Notes:
+ * * the size is specified in bytes.
+ * * the buffer passed should be at least the specified bytes big.
+ * * if the typed arrays are disabled this will return a TypeError.
+ * * if the size is zero or buffer_p is a null pointer this will return an empty SharedArrayBuffer.
+ *
+ * @return value of the construced SharedArrayBuffer object
+ */
+jerry_value_t
+jerry_create_shared_arraybuffer_external (const jerry_length_t size, /**< size of the buffer to used */
+ uint8_t *buffer_p, /**< buffer to use as the SharedArrayBuffer's backing */
+ jerry_value_free_callback_t free_cb) /**< buffer free callback */
+{
+ jerry_assert_api_available ();
+
+#if JERRY_BUILTIN_TYPEDARRAY
+ ecma_object_t *shared_arraybuffer;
+
+ if (JERRY_UNLIKELY (size == 0 || buffer_p == NULL))
+ {
+ shared_arraybuffer = ecma_shared_arraybuffer_new_object (0);
+ }
+ else
+ {
+ shared_arraybuffer = ecma_shared_arraybuffer_new_object_external (size, buffer_p, free_cb);
+ }
+
+ return jerry_return (ecma_make_object_value (shared_arraybuffer));
+#else /* !JERRY_BUILTIN_TYPEDARRAY */
+ JERRY_UNUSED (size);
+ JERRY_UNUSED (buffer_p);
+ JERRY_UNUSED (free_cb);
+ return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_typed_array_not_supported_p)));
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
+} /* jerry_create_shared_arraybuffer_external */
+
+/**
+ * Copy bytes into the ArrayBuffer or SharedArrayBuffer from a buffer.
*
* Note:
- * * if the object passed is not an ArrayBuffer will return 0.
+ * * returns 0, if the passed object is not an ArrayBuffer or SharedArrayBuffer
*
- * @return number of bytes copied into the ArrayBuffer.
+ * @return number of bytes copied into the ArrayBuffer or SharedArrayBuffer.
*/
jerry_length_t
-jerry_arraybuffer_write (const jerry_value_t value, /**< target ArrayBuffer */
+jerry_arraybuffer_write (const jerry_value_t value, /**< target ArrayBuffer or SharedArrayBuffer */
jerry_length_t offset, /**< start offset of the ArrayBuffer */
const uint8_t *buf_p, /**< buffer to copy from */
jerry_length_t buf_size) /**< number of bytes to copy from the buffer */
@@ -5638,7 +5721,7 @@ jerry_arraybuffer_write (const jerry_value_t value, /**< target ArrayBuffer */
jerry_assert_api_available ();
#if JERRY_BUILTIN_TYPEDARRAY
- if (!ecma_is_arraybuffer (value))
+ if (!(ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value)))
{
return 0;
}
@@ -5671,23 +5754,23 @@ jerry_arraybuffer_write (const jerry_value_t value, /**< target ArrayBuffer */
} /* jerry_arraybuffer_write */
/**
- * Copy bytes from a buffer into an ArrayBuffer.
+ * Copy bytes from a buffer into an ArrayBuffer or SharedArrayBuffer.
*
* Note:
- * * if the object passed is not an ArrayBuffer will return 0.
+ * * if the object passed is not an ArrayBuffer or SharedArrayBuffer will return 0.
*
* @return number of bytes read from the ArrayBuffer.
*/
jerry_length_t
-jerry_arraybuffer_read (const jerry_value_t value, /**< ArrayBuffer to read from */
- jerry_length_t offset, /**< start offset of the ArrayBuffer */
+jerry_arraybuffer_read (const jerry_value_t value, /**< ArrayBuffer or SharedArrayBuffer to read from */
+ jerry_length_t offset, /**< start offset of the ArrayBuffer or SharedArrayBuffer */
uint8_t *buf_p, /**< destination buffer to copy to */
jerry_length_t buf_size) /**< number of bytes to copy into the buffer */
{
jerry_assert_api_available ();
#if JERRY_BUILTIN_TYPEDARRAY
- if (!ecma_is_arraybuffer (value))
+ if (!(ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value)))
{
return 0;
}
@@ -5720,20 +5803,20 @@ jerry_arraybuffer_read (const jerry_value_t value, /**< ArrayBuffer to read from
} /* jerry_arraybuffer_read */
/**
- * Get the length (size) of the ArrayBuffer in bytes.
+ * Get the length (size) of the ArrayBuffer or SharedArrayBuffer in bytes.
*
* Note:
- * This is the 'byteLength' property of an ArrayBuffer.
+ * This is the 'byteLength' property of an ArrayBuffer or SharedArrayBuffer.
*
* @return the length of the ArrayBuffer in bytes.
*/
jerry_length_t
-jerry_get_arraybuffer_byte_length (const jerry_value_t value) /**< ArrayBuffer */
+jerry_get_arraybuffer_byte_length (const jerry_value_t value) /**< ArrayBuffer or SharedArrayBuffer */
{
jerry_assert_api_available ();
#if JERRY_BUILTIN_TYPEDARRAY
- if (ecma_is_arraybuffer (value))
+ if (ecma_is_arraybuffer (value) || ecma_is_shared_arraybuffer (value))
{
ecma_object_t *buffer_p = ecma_get_object_from_value (value);
return ecma_arraybuffer_get_length (buffer_p);
@@ -5763,7 +5846,7 @@ jerry_get_arraybuffer_pointer (const jerry_value_t array_buffer) /**< Array Buff
#if JERRY_BUILTIN_TYPEDARRAY
if (ecma_is_value_error_reference (array_buffer)
- || !ecma_is_arraybuffer (array_buffer))
+ || !(ecma_is_arraybuffer (array_buffer) || ecma_is_shared_arraybuffer (array_buffer)))
{
return NULL;
}
diff --git a/jerry-core/ecma/base/ecma-gc.c b/jerry-core/ecma/base/ecma-gc.c
index 75920cc07..a387fe2e7 100644
--- a/jerry-core/ecma/base/ecma-gc.c
+++ b/jerry-core/ecma/base/ecma-gc.c
@@ -1872,6 +1872,7 @@ ecma_gc_free_object (ecma_object_t *object_p) /**< object to free */
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_TYPEDARRAY
case ECMA_OBJECT_CLASS_ARRAY_BUFFER:
+ case ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER:
{
uint32_t arraybuffer_length = ext_object_p->u.cls.u3.length;
diff --git a/jerry-core/ecma/base/ecma-globals.h b/jerry-core/ecma/base/ecma-globals.h
index 7b2f70cf1..11736ae8d 100644
--- a/jerry-core/ecma/base/ecma-globals.h
+++ b/jerry-core/ecma/base/ecma-globals.h
@@ -729,6 +729,7 @@ typedef enum
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_TYPEDARRAY
ECMA_OBJECT_CLASS_ARRAY_BUFFER, /**< Array Buffer (ECMAScript v6, 24.1) */
+ ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER, /**< Shared Array Buffer (ECMAScript v11 24.2) */
#endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_BUILTIN_BIGINT
ECMA_OBJECT_CLASS_BIGINT, /**< Bigint (ECMAScript v11, 4.3.27) */
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c
index 08067bbd0..1ce2a1a63 100644
--- a/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.c
@@ -103,128 +103,7 @@ ecma_builtin_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< thi
return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an ArrayBuffer object"));
}
- /* TODO: step 3. if SharedArrayBuffer will be implemented */
-
- /* 4. */
- if (ecma_arraybuffer_is_detached (object_p))
- {
- return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached));
- }
-
- /* 5. */
- uint32_t len = ecma_arraybuffer_get_length (object_p);
-
- uint32_t start = 0;
- uint32_t end = len;
-
- if (arguments_number > 0)
- {
- /* 6-7. */
- if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (argument_list_p[0],
- len,
- &start)))
- {
- return ECMA_VALUE_ERROR;
- }
-
- if (arguments_number > 1 && !ecma_is_value_undefined (argument_list_p[1]))
- {
- /* 8-9 .*/
- if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (argument_list_p[1],
- len,
- &end)))
- {
- return ECMA_VALUE_ERROR;
- }
- }
- }
-
- /* 10. */
- uint32_t new_len = (end >= start) ? (end - start) : 0;
-
- /* 11. */
- ecma_value_t ctor = ecma_op_species_constructor (object_p, ECMA_BUILTIN_ID_ARRAYBUFFER);
-
- if (ECMA_IS_VALUE_ERROR (ctor))
- {
- return ctor;
- }
-
- /* 12. */
- ecma_object_t *ctor_obj_p = ecma_get_object_from_value (ctor);
- ecma_value_t new_len_value = ecma_make_uint32_value (new_len);
-
- ecma_value_t new_arraybuffer = ecma_op_function_construct (ctor_obj_p, ctor_obj_p, &new_len_value, 1);
-
- ecma_deref_object (ctor_obj_p);
- ecma_free_value (new_len_value);
-
- if (ECMA_IS_VALUE_ERROR (new_arraybuffer))
- {
- return new_arraybuffer;
- }
-
- ecma_object_t *new_arraybuffer_p = ecma_get_object_from_value (new_arraybuffer);
- ecma_value_t ret_value = ECMA_VALUE_EMPTY;
-
- /* 13. */
- if (!ecma_object_class_is (new_arraybuffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER))
- {
- ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Return value is not an ArrayBuffer object"));
- goto free_new_arraybuffer;
- }
-
- /* TODO: step 14. if SharedArrayBuffer will be implemented */
-
- /* 15. */
- if (ecma_arraybuffer_is_detached (new_arraybuffer_p))
- {
- ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Returned ArrayBuffer has been detached"));
- goto free_new_arraybuffer;
- }
-
- /* 16. */
- if (ecma_op_same_value (new_arraybuffer, this_arg))
- {
- ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer subclass returned this from species constructor"));
- goto free_new_arraybuffer;
- }
-
- /* 17. */
- if (ecma_arraybuffer_get_length (new_arraybuffer_p) < new_len)
- {
- ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Derived ArrayBuffer constructor created a too small buffer"));
- goto free_new_arraybuffer;
- }
-
- /* 19. */
- if (ecma_arraybuffer_is_detached (object_p))
- {
- ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Original ArrayBuffer has been detached"));
- goto free_new_arraybuffer;
- }
-
- /* 20. */
- lit_utf8_byte_t *old_buf = ecma_arraybuffer_get_buffer (object_p);
-
- /* 21. */
- lit_utf8_byte_t *new_buf = ecma_arraybuffer_get_buffer (new_arraybuffer_p);
-
- /* 22. */
- memcpy (new_buf, old_buf + start, new_len);
-
-free_new_arraybuffer:
- if (ret_value != ECMA_VALUE_EMPTY)
- {
- ecma_deref_object (new_arraybuffer_p);
- }
- else
- {
- /* 23. */
- ret_value = ecma_make_object_value (new_arraybuffer_p);
- }
-
- return ret_value;
+ return ecma_builtin_arraybuffer_slice (this_arg, argument_list_p, arguments_number);
} /* ecma_builtin_arraybuffer_prototype_object_slice */
/**
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
index eac4e0261..e4724814d 100644
--- a/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h
@@ -164,6 +164,10 @@ OBJECT_VALUE (LIT_MAGIC_STRING_ARRAY_BUFFER_UL,
ECMA_BUILTIN_ID_ARRAYBUFFER,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
+OBJECT_VALUE (LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL,
+ ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER,
+ ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
+
OBJECT_VALUE (LIT_MAGIC_STRING_INT8_ARRAY_UL,
ECMA_BUILTIN_ID_INT8ARRAY,
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.c
new file mode 100644
index 000000000..c8b063288
--- /dev/null
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.c
@@ -0,0 +1,112 @@
+/* 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.
+ */
+
+#include "ecma-builtin-helpers.h"
+#include "ecma-builtins.h"
+#include "ecma-conversion.h"
+#include "ecma-exceptions.h"
+#include "ecma-function-object.h"
+#include "ecma-gc.h"
+#include "ecma-globals.h"
+#include "ecma-helpers.h"
+#include "ecma-objects.h"
+#include "ecma-shared-arraybuffer-object.h"
+#include "ecma-arraybuffer-object.h"
+#include "jrt.h"
+#include "jrt-libc-includes.h"
+
+#if JERRY_BUILTIN_TYPEDARRAY
+
+#define ECMA_BUILTINS_INTERNAL
+#include "ecma-builtins-internal.h"
+
+#define BUILTIN_INC_HEADER_NAME "ecma-builtin-shared-arraybuffer-prototype.inc.h"
+#define BUILTIN_UNDERSCORED_ID shared_arraybuffer_prototype
+#include "ecma-builtin-internal-routines-template.inc.h"
+
+/** \addtogroup ecma ECMA
+ * @{
+ *
+ * \addtogroup ecmabuiltins
+ * @{
+ *
+ * \addtogroup sharedarraybufferprototype ECMA SharedArrayBuffer.prototype object built-in
+ * @{
+ */
+
+/**
+ * The SharedArrayBuffer.prototype.bytelength accessor
+ *
+ * See also:
+ * ES11, 24.2.4.1
+ *
+ * @return ecma value
+ * Returned value must be freed with ecma_free_value.
+ */
+static ecma_value_t
+ecma_builtin_shared_arraybuffer_prototype_bytelength_getter (ecma_value_t this_arg) /**< this argument */
+{
+ if (ecma_is_value_object (this_arg))
+ {
+ ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
+
+ if (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER))
+ {
+ uint32_t len = ecma_arraybuffer_get_length (object_p);
+
+ return ecma_make_uint32_value (len);
+ }
+ }
+
+ return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a SharedArrayBuffer object"));
+} /* ecma_builtin_shared_arraybuffer_prototype_bytelength_getter */
+
+/**
+ * The SharedArrayBuffer.prototype object's 'slice' routine
+ *
+ * See also:
+ * ECMA-262 v11, 24.2.4.3
+ *
+ * @return ecma value
+ * Returned value must be freed with ecma_free_value.
+ */
+static ecma_value_t
+ecma_builtin_shared_arraybuffer_prototype_object_slice (ecma_value_t this_arg, /**< this argument */
+ const ecma_value_t *argument_list_p, /**< arguments list */
+ uint32_t arguments_number) /**< number of arguments */
+{
+ if (!ecma_is_value_object (this_arg))
+ {
+ return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an object"));
+ }
+
+ ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
+
+ /* 2. */
+ if (!ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER))
+ {
+ return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not an SharedArrayBuffer object"));
+ }
+
+ return ecma_builtin_arraybuffer_slice (this_arg, argument_list_p, arguments_number);
+} /* ecma_builtin_shared_arraybuffer_prototype_object_slice */
+
+/**
+ * @}
+ * @}
+ * @}
+ */
+
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h
new file mode 100644
index 000000000..3f2b0bb1b
--- /dev/null
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer-prototype.inc.h
@@ -0,0 +1,47 @@
+/* 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.
+ */
+
+/*
+ * SharedArrayBuffer.prototype built-in description
+ */
+
+#include "ecma-builtin-helpers-macro-defines.inc.h"
+
+#if JERRY_BUILTIN_TYPEDARRAY
+
+/* Object properties:
+ * (property name, object pointer getter) */
+
+OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
+ ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER,
+ ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
+
+/* Readonly accessor properties */
+ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
+ ecma_builtin_shared_arraybuffer_prototype_bytelength_getter,
+ ECMA_PROPERTY_FLAG_CONFIGURABLE)
+
+/* ECMA-262 v11, 24.2.4.4 */
+STRING_VALUE (LIT_GLOBAL_SYMBOL_TO_STRING_TAG,
+ LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL,
+ ECMA_PROPERTY_FLAG_CONFIGURABLE)
+
+/* Routine properties:
+ * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
+ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_shared_arraybuffer_prototype_object_slice, NON_FIXED, 2)
+
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
+
+#include "ecma-builtin-helpers-macro-undefs.inc.h"
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.c b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.c
new file mode 100644
index 000000000..d1c354506
--- /dev/null
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.c
@@ -0,0 +1,95 @@
+/* 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.
+ */
+
+#include "ecma-builtins.h"
+#include "ecma-exceptions.h"
+#include "ecma-gc.h"
+#include "ecma-globals.h"
+#include "ecma-helpers.h"
+#include "ecma-shared-arraybuffer-object.h"
+#include "ecma-dataview-object.h"
+#include "ecma-typedarray-object.h"
+#include "jrt.h"
+
+#if JERRY_BUILTIN_TYPEDARRAY
+
+#define ECMA_BUILTINS_INTERNAL
+#include "ecma-builtins-internal.h"
+
+#define BUILTIN_INC_HEADER_NAME "ecma-builtin-shared-arraybuffer.inc.h"
+#define BUILTIN_UNDERSCORED_ID shared_arraybuffer
+#include "ecma-builtin-internal-routines-template.inc.h"
+
+/** \addtogroup ecma ECMA
+ * @{
+ *
+ * \addtogroup ecmabuiltins
+ * @{
+ *
+ * \addtogroup sharedarraybuffer ECMA SharedArrayBuffer object built-in
+ * @{
+ */
+
+/**
+ * Handle calling [[Call]] of built-in SharedArrayBuffer object
+ *
+ * ES11 24.2.2 SharedArrayBuffer is not intended to be called as
+ * a function and will throw an exception when called in
+ * that manner.
+ *
+ * @return ecma value
+ */
+ecma_value_t
+ecma_builtin_shared_arraybuffer_dispatch_call (const ecma_value_t *arguments_list_p, /**< arguments list */
+ uint32_t arguments_list_len) /**< number of arguments */
+{
+ JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
+
+ return ecma_raise_type_error (ECMA_ERR_MSG ("Constructor SharedArrayBuffer requires 'new'"));
+} /* ecma_builtin_shared_arraybuffer_dispatch_call */
+
+/**
+ * Handle calling [[Construct]] of built-in SharedArrayBuffer object
+ *
+ * @return ecma value
+ */
+ecma_value_t
+ecma_builtin_shared_arraybuffer_dispatch_construct (const ecma_value_t *arguments_list_p, /**< arguments list */
+ uint32_t arguments_list_len) /**< number of arguments */
+{
+ JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
+
+ return ecma_op_create_shared_arraybuffer_object (arguments_list_p, arguments_list_len);
+} /* ecma_builtin_shared_arraybuffer_dispatch_construct */
+
+/**
+ * 24.2.3.2 get SharedArrayBuffer [ @@species ] accessor
+ *
+ * @return ecma_value
+ * returned value must be freed with ecma_free_value
+ */
+ecma_value_t
+ecma_builtin_shared_arraybuffer_species_get (ecma_value_t this_value) /**< This Value */
+{
+ return ecma_copy_value (this_value);
+} /* ecma_builtin_shared_arraybuffer_species_get */
+
+/**
+ * @}
+ * @}
+ * @}
+ */
+
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h
new file mode 100644
index 000000000..41b609f26
--- /dev/null
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-shared-arraybuffer.inc.h
@@ -0,0 +1,52 @@
+/* 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.
+ */
+
+/*
+ * SharedArrayBuffer built-in description
+ */
+
+#include "ecma-builtin-helpers-macro-defines.inc.h"
+
+#if JERRY_BUILTIN_TYPEDARRAY
+
+/* Number properties:
+ * (property name, number value, writable, enumerable, configurable) */
+
+NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
+ 1,
+ ECMA_PROPERTY_FLAG_CONFIGURABLE)
+
+/* Object properties:
+ * (property name, object pointer getter) */
+
+OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
+ ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE,
+ ECMA_PROPERTY_FIXED)
+
+STRING_VALUE (LIT_MAGIC_STRING_NAME,
+ LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL,
+ ECMA_PROPERTY_FLAG_CONFIGURABLE)
+
+/* Routine properties:
+ * (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
+
+/* ES11 24.1.3.3 */
+ACCESSOR_READ_ONLY (LIT_GLOBAL_SYMBOL_SPECIES,
+ ecma_builtin_shared_arraybuffer_species_get,
+ ECMA_PROPERTY_FLAG_CONFIGURABLE)
+
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
+
+#include "ecma-builtin-helpers-macro-undefs.inc.h"
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h
index 65e742708..50929119b 100644
--- a/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h
+++ b/jerry-core/ecma/builtin-objects/ecma-builtins.inc.h
@@ -337,7 +337,21 @@ BUILTIN_ROUTINE (ECMA_BUILTIN_ID_ARRAYBUFFER,
true,
arraybuffer)
- /* The %TypedArrayPrototype% object (ES2015 24.2.3) */
+/* The SharedArrayBuffer.prototype object (ES2015 24.2.4) */
+BUILTIN (ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE,
+ ECMA_OBJECT_TYPE_GENERAL,
+ ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
+ true,
+ shared_arraybuffer_prototype)
+
+/* The SharedArrayBuffer object (ES2015 24.2.2) */
+BUILTIN_ROUTINE (ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER,
+ ECMA_OBJECT_TYPE_NATIVE_FUNCTION,
+ ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE,
+ true,
+ shared_arraybuffer)
+
+/* The %TypedArrayPrototype% object (ES2015 24.2.3) */
BUILTIN (ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE,
ECMA_OBJECT_TYPE_GENERAL,
ECMA_BUILTIN_ID_OBJECT_PROTOTYPE,
diff --git a/jerry-core/ecma/operations/ecma-arraybuffer-object.c b/jerry-core/ecma/operations/ecma-arraybuffer-object.c
index c84696345..7b1486512 100644
--- a/jerry-core/ecma/operations/ecma-arraybuffer-object.c
+++ b/jerry-core/ecma/operations/ecma-arraybuffer-object.c
@@ -13,7 +13,9 @@
* limitations under the License.
*/
+#include "ecma-builtin-helpers.h"
#include "ecma-arraybuffer-object.h"
+#include "ecma-shared-arraybuffer-object.h"
#include "ecma-typedarray-object.h"
#include "ecma-objects.h"
#include "ecma-builtins.h"
@@ -184,7 +186,8 @@ ecma_is_arraybuffer (ecma_value_t target) /**< the target value */
uint32_t JERRY_ATTR_PURE
ecma_arraybuffer_get_length (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */
{
- JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER));
+ JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER));
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
return ecma_arraybuffer_is_detached (object_p) ? 0 : ext_object_p->u.cls.u3.length;
@@ -198,7 +201,8 @@ ecma_arraybuffer_get_length (ecma_object_t *object_p) /**< pointer to the ArrayB
extern inline lit_utf8_byte_t * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
ecma_arraybuffer_get_buffer (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */
{
- JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER));
+ JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER));
ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
@@ -225,7 +229,8 @@ ecma_arraybuffer_get_buffer (ecma_object_t *object_p) /**< pointer to the ArrayB
extern inline bool JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
ecma_arraybuffer_is_detached (ecma_object_t *object_p) /**< pointer to the ArrayBuffer object */
{
- JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER));
+ JERRY_ASSERT (ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (object_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER));
return (((ecma_extended_object_t *) object_p)->u.cls.u1.array_buffer_flags & ECMA_ARRAYBUFFER_DETACHED) != 0;
} /* ecma_arraybuffer_is_detached */
@@ -268,6 +273,142 @@ ecma_arraybuffer_detach (ecma_object_t *object_p) /**< pointer to the ArrayBuffe
return true;
} /* ecma_arraybuffer_detach */
+ecma_value_t
+ecma_builtin_arraybuffer_slice (ecma_value_t this_arg,
+ const ecma_value_t *argument_list_p,
+ uint32_t arguments_number)
+{
+ ecma_object_t *object_p = ecma_get_object_from_value (this_arg);
+
+ /* 4. */
+ if (ecma_arraybuffer_is_detached (object_p))
+ {
+ return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached));
+ }
+
+ /* 5. */
+ uint32_t len = ecma_arraybuffer_get_length (object_p);
+
+ uint32_t start = 0;
+ uint32_t end = len;
+
+ if (arguments_number > 0)
+ {
+ /* 6-7. */
+ if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (argument_list_p[0],
+ len,
+ &start)))
+ {
+ return ECMA_VALUE_ERROR;
+ }
+
+ if (arguments_number > 1 && !ecma_is_value_undefined (argument_list_p[1]))
+ {
+ /* 8-9. */
+ if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (argument_list_p[1],
+ len,
+ &end)))
+ {
+ return ECMA_VALUE_ERROR;
+ }
+ }
+ }
+
+ /* 10. */
+ uint32_t new_len = (end >= start) ? (end - start) : 0;
+
+ /* 11. */
+ ecma_value_t ctor;
+ if (ecma_is_shared_arraybuffer (this_arg))
+ {
+ ctor = ecma_op_species_constructor (object_p, ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER);
+ }
+ else
+ {
+ ctor = ecma_op_species_constructor (object_p, ECMA_BUILTIN_ID_ARRAYBUFFER);
+ }
+
+ if (ECMA_IS_VALUE_ERROR (ctor))
+ {
+ return ctor;
+ }
+
+ /* 12. */
+ ecma_object_t *ctor_obj_p = ecma_get_object_from_value (ctor);
+ ecma_value_t new_len_value = ecma_make_uint32_value (new_len);
+
+ ecma_value_t new_arraybuffer = ecma_op_function_construct (ctor_obj_p, ctor_obj_p, &new_len_value, 1);
+
+ ecma_deref_object (ctor_obj_p);
+ ecma_free_value (new_len_value);
+
+ if (ECMA_IS_VALUE_ERROR (new_arraybuffer))
+ {
+ return new_arraybuffer;
+ }
+
+ ecma_object_t *new_arraybuffer_p = ecma_get_object_from_value (new_arraybuffer);
+ ecma_value_t ret_value = ECMA_VALUE_EMPTY;
+
+ /* 13. */
+ if (!(ecma_object_class_is (new_arraybuffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (new_arraybuffer_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER)))
+ {
+ ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Return value is not an ArrayBuffer object"));
+ goto free_new_arraybuffer;
+ }
+
+ /* 14-15. */
+ if (ecma_arraybuffer_is_detached (new_arraybuffer_p))
+ {
+ ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Returned ArrayBuffer has been detached"));
+ goto free_new_arraybuffer;
+ }
+
+ /* 16. */
+ if (new_arraybuffer == this_arg)
+ {
+ ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer subclass returned this from species constructor"));
+ goto free_new_arraybuffer;
+ }
+
+ /* 17. */
+ if (ecma_arraybuffer_get_length (new_arraybuffer_p) < new_len)
+ {
+ ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Derived ArrayBuffer constructor created a too small buffer"));
+ goto free_new_arraybuffer;
+ }
+
+ /* 19. */
+ if (ecma_arraybuffer_is_detached (object_p))
+ {
+ ret_value = ecma_raise_type_error (ECMA_ERR_MSG ("Original ArrayBuffer has been detached"));
+ goto free_new_arraybuffer;
+ }
+
+ /* 20. */
+ lit_utf8_byte_t *old_buf = ecma_arraybuffer_get_buffer (object_p);
+
+ /* 21. */
+ lit_utf8_byte_t *new_buf = ecma_arraybuffer_get_buffer (new_arraybuffer_p);
+
+ /* 22. */
+ memcpy (new_buf, old_buf + start, new_len);
+
+ free_new_arraybuffer:
+ if (ret_value != ECMA_VALUE_EMPTY)
+ {
+ ecma_deref_object (new_arraybuffer_p);
+ }
+ else
+ {
+ /* 23. */
+ ret_value = ecma_make_object_value (new_arraybuffer_p);
+ }
+
+ return ret_value;
+} /* ecma_builtin_arraybuffer_slice */
+
/**
* @}
* @}
diff --git a/jerry-core/ecma/operations/ecma-arraybuffer-object.h b/jerry-core/ecma/operations/ecma-arraybuffer-object.h
index ca7e8cd63..48cbe078d 100644
--- a/jerry-core/ecma/operations/ecma-arraybuffer-object.h
+++ b/jerry-core/ecma/operations/ecma-arraybuffer-object.h
@@ -49,6 +49,10 @@ bool
ecma_arraybuffer_detach (ecma_object_t *obj_p);
bool
ecma_is_arraybuffer (ecma_value_t val);
+ecma_value_t
+ecma_builtin_arraybuffer_slice (ecma_value_t this_arg,
+ const ecma_value_t *argument_list_p,
+ uint32_t arguments_number);
/**
* @}
diff --git a/jerry-core/ecma/operations/ecma-dataview-object.c b/jerry-core/ecma/operations/ecma-dataview-object.c
index a78145079..45db1e004 100644
--- a/jerry-core/ecma/operations/ecma-dataview-object.c
+++ b/jerry-core/ecma/operations/ecma-dataview-object.c
@@ -16,6 +16,7 @@
#include "jcontext.h"
#include "ecma-function-object.h"
#include "ecma-arraybuffer-object.h"
+#include "ecma-shared-arraybuffer-object.h"
#include "ecma-bigint.h"
#include "ecma-builtins.h"
#include "ecma-exceptions.h"
@@ -60,9 +61,10 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
ecma_object_t *buffer_p = ecma_get_object_from_value (buffer);
- if (!ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER))
+ if (!(ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER)))
{
- return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'buffer' is not an ArrayBuffer"));
+ return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'buffer' is not an ArrayBuffer or SharedArrayBuffer"));
}
/* 3. */
@@ -253,7 +255,8 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
}
ecma_object_t *buffer_p = view_p->buffer_p;
- JERRY_ASSERT (ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER));
+ JERRY_ASSERT (ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (buffer_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER));
/* 3. */
ecma_number_t get_index;
@@ -295,7 +298,6 @@ ecma_op_dataview_get_set_view_value (ecma_value_t view, /**< the operation's 'vi
/* GetViewValue 4., SetViewValue 6. */
bool is_little_endian = ecma_op_to_boolean (is_little_endian_value);
- /* GetViewValue 5 - 6., SetViewValue 7 - 8. */
if (ecma_arraybuffer_is_detached (buffer_p))
{
ecma_free_value (value_to_set);
diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c
index a6ddc6952..6c5ba43a7 100644
--- a/jerry-core/ecma/operations/ecma-objects.c
+++ b/jerry-core/ecma/operations/ecma-objects.c
@@ -2759,6 +2759,7 @@ ecma_object_check_class_name_is_object (ecma_object_t *obj_p) /**< object */
#endif /* JERRY_BUILTIN_PROMISE */
#if JERRY_BUILTIN_TYPEDARRAY
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_ARRAYBUFFER_PROTOTYPE)
+ || ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_TYPEDARRAY_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_INT8ARRAY_PROTOTYPE)
|| ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_UINT8ARRAY_PROTOTYPE)
@@ -2879,6 +2880,7 @@ static const uint16_t ecma_class_object_magic_string_id[] =
#endif /* JERRY_ESNEXT */
#if JERRY_BUILTIN_TYPEDARRAY
LIT_MAGIC_STRING_ARRAY_BUFFER_UL, /**< magic string id of ECMA_OBJECT_CLASS_ARRAY_BUFFER */
+ LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, /**< magic string id of ECMA_OBJECT_CLASS_SHAREDARRAY_BUFFER */
#endif /* JERRY_BUILTIN_TYPEDARRAY */
#if JERRY_BUILTIN_BIGINT
LIT_MAGIC_STRING_BIGINT_UL, /**< magic string id of ECMA_OBJECT_CLASS_BIGINT */
diff --git a/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.c b/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.c
new file mode 100644
index 000000000..cc7c64969
--- /dev/null
+++ b/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.c
@@ -0,0 +1,180 @@
+/* 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.
+ */
+
+#include "ecma-shared-arraybuffer-object.h"
+#include "ecma-typedarray-object.h"
+#include "ecma-objects.h"
+#include "ecma-builtins.h"
+#include "ecma-exceptions.h"
+#include "ecma-gc.h"
+#include "ecma-globals.h"
+#include "ecma-helpers.h"
+#include "jmem.h"
+#include "jcontext.h"
+#include "ecma-function-object.h"
+
+#if JERRY_BUILTIN_TYPEDARRAY
+
+/** \addtogroup ecma ECMA
+ * @{
+ *
+ * \addtogroup ecmasharedarraybufferobject ECMA SharedArrayBuffer object related routines
+ * @{
+ */
+
+/**
+ * Helper function: create SharedArrayBuffer object based on the array length
+ *
+ * The struct of arraybuffer object:
+ * ecma_object_t
+ * extend_part
+ * data buffer
+ *
+ * @return ecma_object_t *
+ */
+ecma_object_t *
+ecma_shared_arraybuffer_new_object (uint32_t length) /**< length of the SharedArrayBuffer */
+{
+ ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE);
+ ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
+ sizeof (ecma_extended_object_t) + length,
+ ECMA_OBJECT_TYPE_CLASS);
+
+ ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) object_p;
+ ext_object_p->u.cls.type = ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER;
+ ext_object_p->u.cls.u1.array_buffer_flags = ECMA_ARRAYBUFFER_INTERNAL_MEMORY;
+ ext_object_p->u.cls.u3.length = length;
+
+ lit_utf8_byte_t *buf = (lit_utf8_byte_t *) (ext_object_p + 1);
+ memset (buf, 0, length);
+
+ return object_p;
+} /* ecma_shared_arraybuffer_new_object */
+
+/**
+ * Helper function: create SharedArrayBuffer object with external buffer backing.
+ *
+ * The struct of external arraybuffer object:
+ * ecma_object_t
+ * extend_part
+ * SharedArrayBuffer external info part
+ *
+ * @return ecma_object_t *, pointer to the created SharedArrayBuffer object
+ */
+ecma_object_t *
+ecma_shared_arraybuffer_new_object_external (uint32_t length, /**< length of the buffer_p to use */
+ void *buffer_p, /**< pointer for SharedArrayBuffer's buffer backing */
+ jerry_value_free_callback_t free_cb) /**< buffer free callback */
+{
+ ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE);
+ ecma_object_t *object_p = ecma_create_object (prototype_obj_p,
+ sizeof (ecma_arraybuffer_external_info),
+ ECMA_OBJECT_TYPE_CLASS);
+
+ ecma_arraybuffer_external_info *array_object_p = (ecma_arraybuffer_external_info *) object_p;
+ array_object_p->extended_object.u.cls.type = ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER;
+ array_object_p->extended_object.u.cls.u1.array_buffer_flags = ECMA_ARRAYBUFFER_EXTERNAL_MEMORY;
+ array_object_p->extended_object.u.cls.u3.length = length;
+
+ array_object_p->buffer_p = buffer_p;
+ array_object_p->free_cb = free_cb;
+
+ return object_p;
+} /* ecma_shared_arraybuffer_new_object_external */
+
+/**
+ * SharedArrayBuffer object creation operation.
+ *
+ * See also: ES11 24.1.1.1
+ *
+ * @return ecma value
+ * Returned value must be freed with ecma_free_value
+ */
+ecma_value_t
+ecma_op_create_shared_arraybuffer_object (const ecma_value_t *arguments_list_p, /**< list of arguments that
+ * are passed to String constructor */
+ uint32_t arguments_list_len) /**< length of the arguments' list */
+{
+ JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
+
+ ecma_object_t *proto_p = ecma_op_get_prototype_from_constructor (JERRY_CONTEXT (current_new_target_p),
+ ECMA_BUILTIN_ID_SHARED_ARRAYBUFFER_PROTOTYPE);
+
+ if (proto_p == NULL)
+ {
+ return ECMA_VALUE_ERROR;
+ }
+
+ ecma_number_t length_num = 0;
+
+ if (arguments_list_len > 0)
+ {
+ if (ecma_is_value_number (arguments_list_p[0]))
+ {
+ length_num = ecma_get_number_from_value (arguments_list_p[0]);
+ }
+ else
+ {
+ ecma_value_t to_number_value = ecma_op_to_number (arguments_list_p[0], &length_num);
+
+ if (ECMA_IS_VALUE_ERROR (to_number_value))
+ {
+ ecma_deref_object (proto_p);
+ return to_number_value;
+ }
+ }
+
+ if (ecma_number_is_nan (length_num))
+ {
+ length_num = 0;
+ }
+
+ const uint32_t maximum_size_in_byte = UINT32_MAX - sizeof (ecma_extended_object_t) - JMEM_ALIGNMENT + 1;
+
+ if (length_num <= -1.0 || length_num > (ecma_number_t) maximum_size_in_byte + 0.5)
+ {
+ ecma_deref_object (proto_p);
+ return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid Shared ArrayBuffer length"));
+ }
+ }
+
+ uint32_t length_uint32 = ecma_number_to_uint32 (length_num);
+ ecma_object_t *shared_array_buffer = ecma_shared_arraybuffer_new_object (length_uint32);
+ ECMA_SET_NON_NULL_POINTER (shared_array_buffer->u2.prototype_cp, proto_p);
+ ecma_deref_object (proto_p);
+
+ return ecma_make_object_value (shared_array_buffer);
+} /* ecma_op_create_shared_arraybuffer_object */
+
+/**
+ * Helper function: check if the target is SharedArrayBuffer
+ *
+ * See also: ES11 24.1.1.4
+ *
+ * @return true - if value is a SharedArrayBuffer object
+ * false - otherwise
+ */
+bool
+ecma_is_shared_arraybuffer (ecma_value_t target) /**< the target value */
+{
+ return (ecma_is_value_object (target)
+ && ecma_object_class_is (ecma_get_object_from_value (target), ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER));
+} /* ecma_is_shared_arraybuffer */
+
+/**
+ * @}
+ * @}
+ */
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
diff --git a/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.h b/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.h
new file mode 100644
index 000000000..2cd04995b
--- /dev/null
+++ b/jerry-core/ecma/operations/ecma-shared-arraybuffer-object.h
@@ -0,0 +1,51 @@
+/* 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.
+ */
+
+#ifndef ECMA_SHARED_ARRAYBUFFER_OBJECT_H
+#define ECMA_SHARED_ARRAYBUFFER_OBJECT_H
+
+#include "ecma-globals.h"
+
+#if JERRY_BUILTIN_TYPEDARRAY
+
+/** \addtogroup ecma ECMA
+ * @{
+ *
+ * \addtogroup ecmasharedarraybufferobject ECMA SharedArrayBuffer object related routines
+ * @{
+ */
+
+ecma_value_t
+ecma_op_create_shared_arraybuffer_object (const ecma_value_t *, uint32_t);
+
+/**
+ * Helper functions for SharedArrayBuffer.
+ */
+ecma_object_t *
+ecma_shared_arraybuffer_new_object (uint32_t lengh);
+ecma_object_t *
+ecma_shared_arraybuffer_new_object_external (uint32_t length,
+ void *buffer_p,
+ jerry_value_free_callback_t free_cb);
+bool
+ecma_is_shared_arraybuffer (ecma_value_t val);
+
+/**
+ * @}
+ * @}
+ */
+
+#endif /* JERRY_BUILTIN_TYPEDARRAY */
+#endif /* !ECMA_SHARED_ARRAYBUFFER_OBJECT_H */
diff --git a/jerry-core/ecma/operations/ecma-typedarray-object.c b/jerry-core/ecma/operations/ecma-typedarray-object.c
index ca7b89003..82b8f3440 100644
--- a/jerry-core/ecma/operations/ecma-typedarray-object.c
+++ b/jerry-core/ecma/operations/ecma-typedarray-object.c
@@ -18,6 +18,7 @@
#include "ecma-iterator-object.h"
#include "ecma-typedarray-object.h"
#include "ecma-arraybuffer-object.h"
+#include "ecma-shared-arraybuffer-object.h"
#include "ecma-function-object.h"
#include "ecma-bigint.h"
#include "ecma-big-uint.h"
@@ -1646,7 +1647,8 @@ ecma_op_create_typedarray (const ecma_value_t *arguments_list_p, /**< the arg li
element_size_shift,
typedarray_id);
}
- else if (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER))
+ else if (ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_ARRAY_BUFFER)
+ || ecma_object_class_is (obj_p, ECMA_OBJECT_CLASS_SHARED_ARRAY_BUFFER))
{
/* 22.2.1.5 */
ecma_object_t *arraybuffer_p = obj_p;
diff --git a/jerry-core/include/jerryscript-core.h b/jerry-core/include/jerryscript-core.h
index c908855d2..f59663004 100644
--- a/jerry-core/include/jerryscript-core.h
+++ b/jerry-core/include/jerryscript-core.h
@@ -383,6 +383,16 @@ uint8_t *jerry_get_arraybuffer_pointer (const jerry_value_t value);
jerry_value_t jerry_is_arraybuffer_detachable (const jerry_value_t value);
jerry_value_t jerry_detach_arraybuffer (const jerry_value_t value);
+/**
+ * SharedArrayBuffer components.
+ */
+
+bool jerry_value_is_shared_arraybuffer (const jerry_value_t value);
+jerry_value_t jerry_create_shared_arraybuffer (const jerry_length_t size);
+jerry_value_t jerry_create_shared_arraybuffer_external (const jerry_length_t size,
+ uint8_t *buffer_p,
+ jerry_value_free_callback_t free_cb);
+
/**
* DataView functions.
*/
diff --git a/jerry-core/include/jerryscript-types.h b/jerry-core/include/jerryscript-types.h
index 31f23df65..4f153e61a 100644
--- a/jerry-core/include/jerryscript-types.h
+++ b/jerry-core/include/jerryscript-types.h
@@ -476,32 +476,33 @@ typedef enum
*/
typedef enum
{
- JERRY_OBJECT_TYPE_NONE = 0u, /**< Non object type */
- JERRY_OBJECT_TYPE_GENERIC, /**< Generic JavaScript object without any internal property */
- JERRY_OBJECT_TYPE_MODULE_NAMESPACE, /**< Namespace object */
- JERRY_OBJECT_TYPE_ARRAY, /**< Array object */
- JERRY_OBJECT_TYPE_PROXY, /**< Proxy object */
- JERRY_OBJECT_TYPE_SCRIPT, /**< Script object (see jerry_parse) */
- JERRY_OBJECT_TYPE_MODULE, /**< Module object (see jerry_parse) */
- JERRY_OBJECT_TYPE_PROMISE, /**< Promise object */
- JERRY_OBJECT_TYPE_DATAVIEW, /**< Dataview object */
- JERRY_OBJECT_TYPE_FUNCTION, /**< Function object (see jerry_function_get_type) */
- JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_get_typedarray_type) */
- JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_get_type) */
- JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */
- JERRY_OBJECT_TYPE_ERROR, /**< Error object */
- JERRY_OBJECT_TYPE_ARRAYBUFFER, /**< Array buffer object */
+ JERRY_OBJECT_TYPE_NONE = 0u, /**< Non object type */
+ JERRY_OBJECT_TYPE_GENERIC, /**< Generic JavaScript object without any internal property */
+ JERRY_OBJECT_TYPE_MODULE_NAMESPACE, /**< Namespace object */
+ JERRY_OBJECT_TYPE_ARRAY, /**< Array object */
+ JERRY_OBJECT_TYPE_PROXY, /**< Proxy object */
+ JERRY_OBJECT_TYPE_SCRIPT, /**< Script object (see jerry_parse) */
+ JERRY_OBJECT_TYPE_MODULE, /**< Module object (see jerry_parse) */
+ JERRY_OBJECT_TYPE_PROMISE, /**< Promise object */
+ JERRY_OBJECT_TYPE_DATAVIEW, /**< Dataview object */
+ JERRY_OBJECT_TYPE_FUNCTION, /**< Function object (see jerry_function_get_type) */
+ JERRY_OBJECT_TYPE_TYPEDARRAY, /**< %TypedArray% object (see jerry_get_typedarray_type) */
+ JERRY_OBJECT_TYPE_ITERATOR, /**< Iterator object (see jerry_iterator_get_type) */
+ JERRY_OBJECT_TYPE_CONTAINER, /**< Container object (see jerry_container_get_type) */
+ JERRY_OBJECT_TYPE_ERROR, /**< Error object */
+ JERRY_OBJECT_TYPE_ARRAYBUFFER, /**< Array buffer object */
+ JERRY_OBJECT_TYPE_SHARED_ARRAY_BUFFER, /**< Shared Array Buffer object */
- JERRY_OBJECT_TYPE_ARGUMENTS, /**< Arguments object */
- JERRY_OBJECT_TYPE_BOOLEAN, /**< Boolean object */
- JERRY_OBJECT_TYPE_DATE, /**< Date object */
- JERRY_OBJECT_TYPE_NUMBER, /**< Number object */
- JERRY_OBJECT_TYPE_REGEXP, /**< RegExp object */
- JERRY_OBJECT_TYPE_STRING, /**< String object */
- JERRY_OBJECT_TYPE_SYMBOL, /**< Symbol object */
- JERRY_OBJECT_TYPE_GENERATOR, /**< Generator object */
- JERRY_OBJECT_TYPE_BIGINT, /**< BigInt object */
- JERRY_OBJECT_TYPE_WEAKREF, /**< WeakRef object */
+ JERRY_OBJECT_TYPE_ARGUMENTS, /**< Arguments object */
+ JERRY_OBJECT_TYPE_BOOLEAN, /**< Boolean object */
+ JERRY_OBJECT_TYPE_DATE, /**< Date object */
+ JERRY_OBJECT_TYPE_NUMBER, /**< Number object */
+ JERRY_OBJECT_TYPE_REGEXP, /**< RegExp object */
+ JERRY_OBJECT_TYPE_STRING, /**< String object */
+ JERRY_OBJECT_TYPE_SYMBOL, /**< Symbol object */
+ JERRY_OBJECT_TYPE_GENERATOR, /**< Generator object */
+ JERRY_OBJECT_TYPE_BIGINT, /**< BigInt object */
+ JERRY_OBJECT_TYPE_WEAKREF, /**< WeakRef object */
} jerry_object_type_t;
/**
diff --git a/jerry-core/lit/lit-magic-strings.inc.h b/jerry-core/lit/lit-magic-strings.inc.h
index 7f1234dea..9227621db 100644
--- a/jerry-core/lit/lit-magic-strings.inc.h
+++ b/jerry-core/lit/lit-magic-strings.inc.h
@@ -967,6 +967,7 @@ LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_NEGATIVE_INFINITY_U, "NEGATIVE_INFINITY")
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_POSITIVE_INFINITY_U, "POSITIVE_INFINITY")
#endif
#if JERRY_BUILTIN_TYPEDARRAY
+LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL, "SharedArrayBuffer")
LIT_MAGIC_STRING_DEF (LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL, "Uint8ClampedArray")
#endif
#if JERRY_BUILTIN_DATE
@@ -1166,7 +1167,7 @@ LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_GENERATOR_FUNCTION
#elif JERRY_BUILTIN_NUMBER
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_NEGATIVE_INFINITY_U)
#elif JERRY_BUILTIN_TYPEDARRAY
-LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL)
+LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL)
#elif JERRY_BUILTIN_DATE
LIT_MAGIC_STRING_FIRST_STRING_WITH_SIZE (17, LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL)
#else
diff --git a/jerry-core/lit/lit-magic-strings.ini b/jerry-core/lit/lit-magic-strings.ini
index afd9f3a59..83f1e54f3 100644
--- a/jerry-core/lit/lit-magic-strings.ini
+++ b/jerry-core/lit/lit-magic-strings.ini
@@ -391,6 +391,7 @@ LIT_MAGIC_STRING_BYTES_PER_ELEMENT_U = "BYTES_PER_ELEMENT"
LIT_MAGIC_STRING_NEGATIVE_INFINITY_U = "NEGATIVE_INFINITY"
LIT_MAGIC_STRING_POSITIVE_INFINITY_U = "POSITIVE_INFINITY"
LIT_MAGIC_STRING_GENERATOR_FUNCTION_UL = "GeneratorFunction"
+LIT_MAGIC_STRING_SHARED_ARRAY_BUFFER_UL = "SharedArrayBuffer"
LIT_MAGIC_STRING_UINT8_CLAMPED_ARRAY_UL = "Uint8ClampedArray"
LIT_MAGIC_STRING_GET_TIMEZONE_OFFSET_UL = "getTimezoneOffset"
LIT_MAGIC_STRING_PREVENT_EXTENSIONS_UL = "preventExtensions"
diff --git a/tests/jerry/es.next/length-property.js b/tests/jerry/es.next/length-property.js
index 5a9230a1c..ec85f64e5 100644
--- a/tests/jerry/es.next/length-property.js
+++ b/tests/jerry/es.next/length-property.js
@@ -30,6 +30,7 @@ var builtin_objects = [
ReferenceError,
RegExp,
Set,
+ SharedArrayBuffer,
String,
Symbol,
SyntaxError,
diff --git a/tests/jerry/es.next/object-prototype-tostring.js b/tests/jerry/es.next/object-prototype-tostring.js
index b8e58279d..0c8f94626 100644
--- a/tests/jerry/es.next/object-prototype-tostring.js
+++ b/tests/jerry/es.next/object-prototype-tostring.js
@@ -45,6 +45,17 @@ assert (Object.prototype.toString.call (new ArrayBuffer ()) === "[object myStrin
ArrayBuffer.prototype[Symbol.toStringTag] = {};
assert (ArrayBuffer.prototype.toString.call (new ArrayBuffer ()) === "[object Object]");
+/* SharedArrayBuffer.prototype @@toStringTag */
+assert (SharedArrayBuffer.prototype[Symbol.toStringTag] === "SharedArrayBuffer");
+assert (Object.prototype.toString.call (new SharedArrayBuffer ()) === "[object SharedArrayBuffer]");
+
+assert (delete SharedArrayBuffer.prototype[Symbol.toStringTag]);
+assert (SharedArrayBuffer.prototype[Symbol.toStringTag] === undefined);
+SharedArrayBuffer.prototype[Symbol.toStringTag] = "myStringTag3";
+assert (Object.prototype.toString.call (new SharedArrayBuffer ()) === "[object myStringTag3]");
+SharedArrayBuffer.prototype[Symbol.toStringTag] = {};
+assert (SharedArrayBuffer.prototype.toString.call (new SharedArrayBuffer ()) === "[object Object]");
+
/* Promise.prototype @@toStringTag */
assert (Promise.prototype[Symbol.toStringTag] === "Promise");
assert (Object.prototype.toString.call (new Promise (function () {})) === "[object Promise]");
diff --git a/tests/jerry/es.next/typedArray-fill.js b/tests/jerry/es.next/typedArray-fill.js
index a8509be28..ebe071e83 100644
--- a/tests/jerry/es.next/typedArray-fill.js
+++ b/tests/jerry/es.next/typedArray-fill.js
@@ -113,22 +113,26 @@ var l = new BigUint64Array([1n, 2n, 3n, 4n, 5n]);
assert(l.fill(-18446744073709551614n, 3, 5).toString() === '1,2,3,2,2');
assert(l.fill(18446744073709551614n, 4).toString() === '1,2,3,2,18446744073709551614');
+var cd = new SharedArrayBuffer(4);
+var u8array = new Uint8Array(cd);
+assert(u8array.fill(0).toString() === '0,0,0,0');
+
var invalid = {
valueOf: function() {
throw new Error();
}
};
-var m = new BigInt64Array();
+var n = new BigInt64Array();
try {
- m.fill(1n, invalid);
+ n.fill(1n, invalid);
assert(false)
} catch (e) {
assert(e instanceof Error);
}
try {
- m.fill(1n, 0, invalid);
+ n.fill(1n, 0, invalid);
assert(false)
} catch (e) {
assert(e instanceof Error);
diff --git a/tests/jerry/es.next/typedArray-subarray.js b/tests/jerry/es.next/typedArray-subarray.js
index 57bf77188..e91685663 100644
--- a/tests/jerry/es.next/typedArray-subarray.js
+++ b/tests/jerry/es.next/typedArray-subarray.js
@@ -46,3 +46,20 @@ assert(c.subarray(4, 1).toString() === '');
assert(c.subarray(-1, -4).toString() === '');
assert(c.subarray(1).subarray(1).toString() === '3,4,5');
assert(c.subarray(1, 4).subarray(1, 2).toString() === '3');
+
+var cd = new SharedArrayBuffer(28);
+tmp = new Int32Array(cd);
+tmp.set([0, 1, 2, 3, 4, 5, 0]);
+var d = new Int32Array(cd, 4, 5);
+assert(d.subarray().toString() === '1,2,3,4,5');
+assert(d.subarray(3).toString() === '4,5');
+assert(d.subarray(1, 3).toString() === '2,3');
+assert(d.subarray(1, 3).toString() === '2,3');
+assert(d.subarray(-3).toString() === '3,4,5');
+assert(d.subarray(-3, -1).toString() === '3,4');
+assert(d.subarray(3, 2).toString() === '');
+assert(d.subarray(-2, -3).toString() === '');
+assert(d.subarray(4, 1).toString() === '');
+assert(d.subarray(-1, -4).toString() === '');
+assert(d.subarray(1).subarray(1).toString() === '3,4,5');
+assert(d.subarray(1, 4).subarray(1, 2).toString() === '3');
diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml
index 7ca71941c..065e7e2d3 100644
--- a/tests/test262-esnext-excludelist.xml
+++ b/tests/test262-esnext-excludelist.xml
@@ -5514,8 +5514,6 @@
features: [SharedArrayBuffer]
https://github.com/tc39/ecmascript_sharedmem
-->
-
-
@@ -5746,161 +5744,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-