From 09d8e9e67f72efd574a2a663feca95dabf5a08e6 Mon Sep 17 00:00:00 2001 From: wuwenlu Date: Sun, 7 Apr 2024 19:20:56 +0800 Subject: [PATCH 1/3] support Atomics.waitAsync for ECMA2024 patch 1 Signed-off-by: wuwenlu --- ...ker_wait_async_bigint_false_for_timeout.js | 40 +++++++++++++++ .../worker_wait_async_bigint_good_views.js | 46 +++++++++++++++++ ...orker_wait_async_bigint_nan_for_timeout.js | 24 +++++++++ ...rker_wait_async_bigint_negative_timeout.js | 23 +++++++++ ..._bigint_no_spurious_wakeup_no_operation.js | 27 ++++++++++ ..._async_bigint_no_spurious_wakeup_on_add.js | 29 +++++++++++ ...rker_wait_async_bigint_null_for_timeout.js | 40 +++++++++++++++ ...er_wait_async_bigint_object_for_timeout.js | 45 ++++++++++++++++ ...gint_poisoned_object_for_timeout_throws.js | 49 ++++++++++++++++++ ...it_async_bigint_symbol_for_index_throws.js | 50 ++++++++++++++++++ ..._async_bigint_symbol_for_timeout_throws.js | 38 ++++++++++++++ ...it_async_bigint_symbol_for_value_throws.js | 51 +++++++++++++++++++ ...rker_wait_async_bigint_true_for_timeout.js | 37 ++++++++++++++ ...it_async_bigint_undefined_for_timeout01.js | 26 ++++++++++ ...it_async_bigint_undefined_for_timeout02.js | 27 ++++++++++ ...gint_undefined_index_defaults_to_zero01.js | 25 +++++++++ ...gint_undefined_index_defaults_to_zero02.js | 25 +++++++++ ...orker_wait_async_bigint_value_not_equal.js | 24 +++++++++ ...aiterlist_block_indexed_position_wake01.js | 26 ++++++++++ ...aiterlist_block_indexed_position_wake02.js | 26 ++++++++++ ...t_async_bigint_was_woken_before_timeout.js | 29 +++++++++++ .../worker_wait_async_false_for_timeout.js | 35 +++++++++++++ .../workers/worker_wait_async_good_views.js | 47 +++++++++++++++++ .../worker_wait_async_nan_for_timeout.js | 24 +++++++++ .../worker_wait_async_negative_timeout.js | 23 +++++++++ ...t_async_no_spurious_wakeup_no_operation.js | 27 ++++++++++ ...er_wait_async_no_spurious_wakeup_on_add.js | 29 +++++++++++ .../worker_wait_async_null_for_timeout.js | 40 +++++++++++++++ .../worker_wait_async_object_for_timeout.js | 45 ++++++++++++++++ ...sync_poisoned_object_for_timeout_throws.js | 50 ++++++++++++++++++ ...rker_wait_async_symbol_for_index_throws.js | 50 ++++++++++++++++++ ...er_wait_async_symbol_for_timeout_throws.js | 38 ++++++++++++++ ...rker_wait_async_symbol_for_value_throws.js | 50 ++++++++++++++++++ .../worker_wait_async_true_for_timeout.js | 37 ++++++++++++++ ...rker_wait_async_undefined_for_timeout01.js | 25 +++++++++ ...rker_wait_async_undefined_for_timeout02.js | 25 +++++++++ ...sync_undefined_index_defaults_to_zero01.js | 25 +++++++++ ...sync_undefined_index_defaults_to_zero02.js | 25 +++++++++ .../worker_wait_async_value_not_equal.js | 24 +++++++++ ...aiterlist_block_indexed_position_wake01.js | 26 ++++++++++ ...aiterlist_block_indexed_position_wake02.js | 26 ++++++++++ ...ker_wait_async_was_woken_before_timeout.js | 29 +++++++++++ 42 files changed, 1407 insertions(+) create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_false_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_good_views.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_nan_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_negative_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_no_operation.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_null_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_object_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_poisoned_object_for_timeout_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_index_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_timeout_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_value_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_true_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout01.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout02.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero01.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero02.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_value_not_equal.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake01.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake02.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_was_woken_before_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_false_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_good_views.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_nan_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_negative_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_no_operation.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_null_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_object_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_poisoned_object_for_timeout_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_index_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_timeout_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_value_throws.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_true_for_timeout.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout01.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout02.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero01.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero02.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_value_not_equal.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake01.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake02.js create mode 100644 commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_was_woken_before_timeout.js diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_false_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_false_for_timeout.js new file mode 100644 index 0000000000..1aa96cdb79 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_false_for_timeout.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const valueOf = { + valueOf() { + return false; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return false; + } +}; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, false).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, false).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_good_views.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_good_views.js new file mode 100644 index 0000000000..0a7b103eb0 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_good_views.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var sab = new SharedArrayBuffer(2048); + var good_indices = [(view) => 0 / -1, // -0 + (view) => '-0', + (view) => view.length - 1, + (view) => ({ valueOf: () => 0 }), + // non-callable valueOf triggers invocation of toString + (view) => ({ toString: () => '0', valueOf: false }) + ]; + + var view = new BigInt64Array(sab, 32, 20); + + view[0] = 0n; + parentPort.postMessage("A " + (await Atomics.waitAsync(view, 0, 0n, 0).value)) + parentPort.postMessage("B " + (await Atomics.waitAsync(view, 0, 37n, 0).value)); + + const results = []; + // In-bounds boundary cases for indexing + for (let IdxGen of good_indices) { + let Idx = IdxGen(view); + view.fill(0n); + // Atomics.store() computes an index from Idx in the same way as other + // Atomics operations, not quite like view[Idx]. + Atomics.store(view, Idx, 37n); + results.push(await Atomics.waitAsync(view, Idx, 0n).value); + } + parentPort.postMessage("C " + results.join(",")); +} diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_nan_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_nan_for_timeout.js new file mode 100644 index 0000000000..6862379364 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_nan_for_timeout.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + parentPort.postMessage("success"); + var i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, NaN).value); // NaN => +Infinity +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_negative_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_negative_timeout.js new file mode 100644 index 0000000000..6bc23eee4a --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_negative_timeout.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, -5).value); // NaN => +Infinity +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_no_operation.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_no_operation.js new file mode 100644 index 0000000000..f9f642acd5 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_no_operation.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + Atomics.add(i64a, 1, 1n); + const before = new Date().getTime(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, 200).value; + const duration = new Date().getTime() - before; + parentPort.postMessage(duration); + parentPort.postMessage(unpark); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js new file mode 100644 index 0000000000..a8fb316282 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 1, 1n); + const before = new Date().getTime(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, 200).value; + const duration = new Date().getTime() - before; + console.log("duration = " + duration); + parentPort.postMessage(duration); + parentPort.postMessage(unpark); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_null_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_null_for_timeout.js new file mode 100644 index 0000000000..57d36ee252 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_null_for_timeout.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const valueOf = { + valueOf() { + return null; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return null; + } +}; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, null).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, null).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_object_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_object_for_timeout.js new file mode 100644 index 0000000000..c2d313de09 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_object_for_timeout.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; +const valueOf = { + valueOf() { + return 0; + } +}; + +const toString = { + toString() { + return "0"; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return 0; + } +}; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, toString).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, toString).value); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_poisoned_object_for_timeout_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_poisoned_object_for_timeout_throws.js new file mode 100644 index 0000000000..cb606a4a42 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_poisoned_object_for_timeout_throws.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const poisonedValueOf = { + valueOf() { + throw new Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Error('passing a poisoned object using @@ToPrimitive'); + } +}; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + Atomics.add(i64a, 1, 1n); + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i64a, 0, 0n, poisonedValueOf); + } catch (error) { + status1 = 'poisonedValueOf'; + } + try { + Atomics.waitAsync(i64a, 0, 0n, poisonedToPrimitive); + } catch (error) { + status2 = 'poisonedToPrimitive'; + } + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_index_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_index_throws.js new file mode 100644 index 0000000000..d18b4fb3ab --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_index_throws.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const poisonedValueOf = { + valueOf() { + throw new Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Error('should not evaluate this code'); + } +}; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + Atomics.add(i64a, 1, 1n); + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i64a, Symbol('1'), poisonedValueOf, poisonedValueOf); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i64a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive); + } catch (error) { + status2 = 'B ' + error.name; + } + + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_timeout_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_timeout_throws.js new file mode 100644 index 0000000000..84e104968d --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_timeout_throws.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + Atomics.add(i64a, 1, 1n); + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i64a, 0, 0n, Symbol('1')); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i64a, 0, 0n, Symbol('2')); + } catch (error) { + status2 = 'B ' + error.name; + } + + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_value_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_value_throws.js new file mode 100644 index 0000000000..fff20a31dc --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_symbol_for_value_throws.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const poisonedValueOf = { + valueOf: function () { + throw new Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]: function () { + throw new Error("passing a poisoned object using @@ToPrimitive"); + } +}; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + Atomics.add(i64a, 1, 1n); + + let status1 = ""; + let status2 = ""; + + try { + Atomics.waitAsync(i64a, 0, Symbol("1"), poisonedValueOf); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i64a, 0, Symbol("2"), poisonedToPrimitive); + } catch (error) { + status2 = 'B ' + error.name; + } + + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_true_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_true_for_timeout.js new file mode 100644 index 0000000000..efac4de850 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_true_for_timeout.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const valueOf = { + valueOf() { + return true; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } +}; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, true).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout01.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout01.js new file mode 100644 index 0000000000..f16ab59141 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout01.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 1, 1n); + + // undefined => NaN => +Infinity + parentPort.postMessage("A " + (await Atomics.waitAsync(i64a, 0, 0n, undefined).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout02.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout02.js new file mode 100644 index 0000000000..0a1a772c0c --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_for_timeout02.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 1, 1n); + + // undefined timeout arg => NaN => +Infinity + parentPort.postMessage("B " + (await Atomics.waitAsync(i64a, 0, 0n).value)); + +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero01.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero01.js new file mode 100644 index 0000000000..fc5e9dca14 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero01.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 1, 1n); + // undefined => NaN => +Infinity + parentPort.postMessage("A " + (await Atomics.waitAsync(i64a, undefined, 0n).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero02.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero02.js new file mode 100644 index 0000000000..16e0155638 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero02.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 1, 1n); + // undefined => NaN => +Infinity + parentPort.postMessage("B " + (await Atomics.waitAsync(i64a, undefined, 0n).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_value_not_equal.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_value_not_equal.js new file mode 100644 index 0000000000..f3cb3d7bd7 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_value_not_equal.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function (e) { + var i64a = e.data; + Atomics.add(i64a, 1, 1n); + parentPort.postMessage(Atomics.store(i64a, 0, 42n)); + parentPort.postMessage(Atomics.waitAsync(i64a, 0, 0n).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake01.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake01.js new file mode 100644 index 0000000000..b11c6121d0 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake01.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 4, 1n); + // Wait on index 0 + parentPort.postMessage(await Atomics.waitAsync(i64a, 0, 0n, Infinity).value); + parentPort.close(); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake02.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake02.js new file mode 100644 index 0000000000..09e54647a3 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake02.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 4, 1n); + // Wait on index 2 + parentPort.postMessage(await Atomics.waitAsync(i64a, 2, 0n, Infinity).value); + parentPort.close(); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_was_woken_before_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_was_woken_before_timeout.js new file mode 100644 index 0000000000..c23cf32d19 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_bigint_was_woken_before_timeout.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + const i64a = e.data; + parentPort.postMessage("success"); + Atomics.add(i64a, 1, 1n); + const before = new Date().getTime(); + const unpark = await Atomics.waitAsync(i64a, 0, 0n, 10000).value; + const duration = new Date().getTime() - before; + + parentPort.postMessage(duration); + parentPort.postMessage(unpark); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_false_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_false_for_timeout.js new file mode 100644 index 0000000000..ab2e67afba --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_false_for_timeout.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function (e) { + const valueOf = { + valueOf() { + return false; + } + }; + const toPrimitive = { + [Symbol.toPrimitive]() { + return false; + } + }; + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, false).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, valueOf).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_good_views.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_good_views.js new file mode 100644 index 0000000000..ebf4e94815 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_good_views.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function (e) { + (async () => { + var sab = new SharedArrayBuffer(1024); + var good_indices = [(view) => 0 / -1, // -0 + (view) => '-0', + (view) => view.length - 1, + (view) => ({ valueOf: () => 0 }), + (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString + ]; + + var view = new Int32Array(sab, 32, 20); + + view[0] = 0; + parentPort.postMessage("A " + (await Atomics.waitAsync(view, 0, 0, 0).value)) + parentPort.postMessage("B " + (await Atomics.waitAsync(view, 0, 37, 0).value)); + + const results = []; + // In-bounds boundary cases for indexing + for (let IdxGen of good_indices) { + let Idx = IdxGen(view); + view.fill(0); + // Atomics.store() computes an index from Idx in the same way as other + // Atomics operations, not quite like view[Idx]. + Atomics.store(view, Idx, 37); + results.push(await Atomics.waitAsync(view, Idx, 0).value); + } + parentPort.postMessage("C " + results.join(",")); + })(); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_nan_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_nan_for_timeout.js new file mode 100644 index 0000000000..24e690b3b2 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_nan_for_timeout.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + parentPort.postMessage("success"); + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, NaN).value); // NaN => +Infinity +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_negative_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_negative_timeout.js new file mode 100644 index 0000000000..a2df4ea943 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_negative_timeout.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, -5).value); // NaN => +Infinity +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_no_operation.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_no_operation.js new file mode 100644 index 0000000000..520e0457f6 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_no_operation.js @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + const before = new Date().getTime(); + const unpark = await Atomics.waitAsync(i32a, 0, 0, 200).value; + const duration = new Date().getTime() - before; + parentPort.postMessage(duration); + parentPort.postMessage(unpark); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js new file mode 100644 index 0000000000..b5eefd71e7 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 1, 1); + const before = new Date().getTime(); + const unpark = await Atomics.waitAsync(i32a, 0, 0, 200).value; + const duration = new Date().getTime() - before; + console.log("duration = " + duration); + parentPort.postMessage(duration); + parentPort.postMessage(unpark); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_null_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_null_for_timeout.js new file mode 100644 index 0000000000..6b64eaba6a --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_null_for_timeout.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + const valueOf = { + valueOf() { + return null; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return null; + } + }; + + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, null).value); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, null).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, valueOf).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_object_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_object_for_timeout.js new file mode 100644 index 0000000000..3583604720 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_object_for_timeout.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; +const valueOf = { + valueOf() { + return 0; + } +}; + +const toString = { + toString() { + return "0"; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return 0; + } +}; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, toString).value); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, valueOf).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, toString).value); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_poisoned_object_for_timeout_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_poisoned_object_for_timeout_throws.js new file mode 100644 index 0000000000..de74425e85 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_poisoned_object_for_timeout_throws.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + const poisonedValueOf = { + valueOf() { + throw new Error('should not evaluate this code'); + } + }; + + const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Error('passing a poisoned object using @@ToPrimitive'); + } + }; + + var i32a = e.data; + Atomics.add(i32a, 1, 1); + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i32a, 0, 0, poisonedValueOf); + } catch (error) { + status1 = 'poisonedValueOf'; + } + try { + Atomics.waitAsync(i32a, 0, 0, poisonedToPrimitive); + } catch (error) { + status2 = 'poisonedToPrimitive'; + } + parentPort.postMessage(status1); + parentPort.postMessage(status2); + +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_index_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_index_throws.js new file mode 100644 index 0000000000..a2d4269cb1 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_index_throws.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const poisonedValueOf = { + valueOf() { + throw new Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Error('should not evaluate this code'); + } +}; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i32a, Symbol('1'), poisonedValueOf, poisonedValueOf); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i32a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive); + } catch (error) { + status2 = 'B ' + error.name; + } + + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_timeout_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_timeout_throws.js new file mode 100644 index 0000000000..dbde72bfa0 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_timeout_throws.js @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + let status1 = ''; + let status2 = ''; + + try { + Atomics.waitAsync(i32a, 0, 0, Symbol('1')); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i32a, 0, 0, Symbol('2')); + } catch (error) { + status2 = 'B ' + error.name; + } + + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_value_throws.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_value_throws.js new file mode 100644 index 0000000000..d954506d76 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_symbol_for_value_throws.js @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const poisonedValueOf = { + valueOf() { + throw new Error('should not evaluate this code'); + } +}; + +const poisonedToPrimitive = { + [Symbol.toPrimitive]() { + throw new Error('should not evaluate this code'); + } +}; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + let status1 = ""; + let status2 = ""; + + try { + Atomics.waitAsync(i32a, 0, Symbol("1"), poisonedValueOf); + } catch (error) { + status1 = 'A ' + error.name; + } + try { + Atomics.waitAsync(i32a, 0, Symbol("2"), poisonedToPrimitive); + } catch (error) { + status2 = 'B ' + error.name; + } + + parentPort.postMessage(status1); + parentPort.postMessage(status2); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_true_for_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_true_for_timeout.js new file mode 100644 index 0000000000..87a939bc50 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_true_for_timeout.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +const valueOf = { + valueOf() { + return true; + } +}; + +const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } +}; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, true).value); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, valueOf).value); + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout01.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout01.js new file mode 100644 index 0000000000..f6db7766bd --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout01.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 1, 1); + // undefined => NaN => +Infinity + parentPort.postMessage("A " + (await Atomics.waitAsync(i32a, 0, 0, undefined).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout02.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout02.js new file mode 100644 index 0000000000..5ed4c7557b --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_for_timeout02.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 1, 1); + // undefined timeout arg => NaN => +Infinity + parentPort.postMessage("B " + (await Atomics.waitAsync(i32a, 0, 0).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero01.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero01.js new file mode 100644 index 0000000000..52045bbf63 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero01.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 1, 1); + // undefined => NaN => +Infinity + parentPort.postMessage("A " + (await Atomics.waitAsync(i32a, undefined, 0).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero02.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero02.js new file mode 100644 index 0000000000..d34da60d79 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_undefined_index_defaults_to_zero02.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 1, 1); + // undefined timeout arg => NaN => +Infinity + parentPort.postMessage("B " + (await Atomics.waitAsync(i32a, undefined, 0).value)); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_value_not_equal.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_value_not_equal.js new file mode 100644 index 0000000000..5c7f24731e --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_value_not_equal.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function (e) { + var i32a = e.data; + Atomics.add(i32a, 1, 1); + parentPort.postMessage(Atomics.store(i32a, 0, 42)); + parentPort.postMessage(Atomics.waitAsync(i32a, 0, 0).value); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake01.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake01.js new file mode 100644 index 0000000000..b929e2bd39 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake01.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 4, 1); + // Wait on index 0 + parentPort.postMessage(await Atomics.waitAsync(i32a, 0, 0, Infinity).value); + parentPort.close(); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake02.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake02.js new file mode 100644 index 0000000000..2c8318558c --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake02.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 4, 1); + // Wait on index 2 + parentPort.postMessage(await Atomics.waitAsync(i32a, 2, 0, Infinity).value); + parentPort.close(); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_was_woken_before_timeout.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_was_woken_before_timeout.js new file mode 100644 index 0000000000..567d9b5e30 --- /dev/null +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/workers/worker_wait_async_was_woken_before_timeout.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * 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. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = async function (e) { + var i32a = e.data; + parentPort.postMessage("success"); + Atomics.add(i32a, 1, 1); + const before = new Date().getTime(); + const unpark = await Atomics.waitAsync(i32a, 0, 0, 10000).value; + const duration = new Date().getTime() - before; + + parentPort.postMessage(duration); + parentPort.postMessage(unpark); +} \ No newline at end of file -- Gitee From 76707492f8add595fbd5fb7a98ebbeb2ac49a647 Mon Sep 17 00:00:00 2001 From: wuwenlu Date: Sun, 7 Apr 2024 19:21:30 +0800 Subject: [PATCH 2/3] support Atomics.waitAsync for ECMA2024 patch 2 Signed-off-by: wuwenlu --- .../entry/src/main/ets/test/Atomics.test.js | 1416 ++++++++++++++++- 1 file changed, 1404 insertions(+), 12 deletions(-) diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js index 277e07318a..be0ff91239 100644 --- a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js @@ -34,11 +34,15 @@ export default function WaitTest() { } /** - * @tc.name: testNotify001 - * @tc.desc: returns a string which is either "ok", "not-equal", or "timed-out". - * @tc.author: jiangkai + * @tc.number SUB_COMMONLIBRARY_ATOMICS_NOTIFY_001 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_NOTIFY_001 + * @tc.desc returns a string which is either "ok", "not-equal", or "timed-out". + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + * @tc.author jiangkai */ - it('testNotify001', 0, async function (done) { + it('SUB_COMMONLIBRARY_ATOMICS_NOTIFY_001', 0, async function (done) { var sab = new SharedArrayBuffer(20); var int32 = new Int32Array(sab); var flag = false @@ -122,11 +126,15 @@ export default function WaitTest() { }) /** - * @tc.name: testWait001 - * @tc.desc: returns a string which is either "ok", "not-equal", or "timed-out". - * @tc.author: jiangkai + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAIT_001 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAIT_001 + * @tc.desc returns a string which is either "ok", "not-equal", or "timed-out". + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + * @tc.author jiangkai */ - it('testWait001', 0, async function (done) { + it('SUB_COMMONLIBRARY_ATOMICS_WAIT_001', 0, async function (done) { var sab = new SharedArrayBuffer(20); var flag = false; var int32 = new Int32Array(sab); @@ -168,11 +176,15 @@ export default function WaitTest() { }) /** - * @tc.name: testAdd001 - * @tc.desc: returns a string which is either "ok", "not-equal", or "timed-out". - * @tc.author: jiangkai + * @tc.number SUB_COMMONLIBRARY_ATOMICS_ADD_001 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_ADD_001 + * @tc.desc returns a string which is either "ok", "not-equal", or "timed-out". + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + * @tc.author jiangkai */ - it('testAdd001', 0, async function (done) { + it('SUB_COMMONLIBRARY_ATOMICS_ADD_001', 0, async function (done) { var sab = new SharedArrayBuffer(20); var int32 = new Uint32Array(sab); int32[0] = 1; @@ -215,5 +227,1385 @@ export default function WaitTest() { expect(int32[0]).assertEqual(21) done() }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_001 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_001 + * @tc.desc False timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_001', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/false-for-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_false_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(3); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_002 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_002 + * @tc.desc Test Atomics.waitAsync on arrays that allow atomic operations + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_002', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/good-views.js + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_good_views.js"); + + ss.onmessage = function (e) { + if (e.data == 'A timed-out' || e.data == 'B not-equal' + || e.data == 'C not-equal,not-equal,not-equal,not-equal,not-equal') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + ss.postMessage("start"); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(3); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_003 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_003 + * @tc.desc Undefined timeout arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_003', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/implicit-infinity-for-timeout.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + let { async, value } = Atomics.waitAsync(i32a, 0, 0); + + value.then(result => { + expect(result).assertEqual("ok"); + done(); + }) + + Atomics.notify(i32a, 0); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_004 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_004 + * @tc.desc NaN timeout arg should result in an infinite timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_004', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/nan-for-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_nan_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == 'ok') { + res = e.data; + } + flag = true; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + + flag = false; + expect(Atomics.notify(i32a, 0)).assertEqual(1); + while (!flag) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(res).assertEqual('ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_005 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_005 + * @tc.desc Test that Atomics.waitAsync returns the right result when it timed out + * and that the time to time out is reasonable. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_005', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-no-operation.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_no_operation.js"); + + ss.onmessage = function (e) { + if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_006 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_006 + * @tc.desc Waiter does not spuriously notify on index which is subject to Add operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_006', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-add.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.add(i32a, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_007 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_007 + * @tc.desc Waiter does not spuriously notify on index which is subject to And operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_007', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-and.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.and(i32a, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_008 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_008 + * @tc.desc Waiter does not spuriously notify on index which is subject to compareExchange operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_008', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-compareExchange.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.compareExchange(i32a, 0, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_009 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_009 + * @tc.desc Test that Atomics.waitAsync times out with a negative timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_009', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/negative-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_negative_timeout.js"); + + ss.onmessage = function (e) { + res = e.data; + flag = true; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_010 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_010 + * @tc.desc Waiter does not spuriously notify on index which is subject to exchange operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_010', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-exchange.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.exchange(i32a, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_011 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_011 + * @tc.desc Waiter does not spuriously notify on index which is subject to Or operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_011', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-or.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.or(i32a, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_012 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_012 + * @tc.desc Waiter does not spuriously notify on index which is subject to Sub operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_012', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-sub.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.sub(i32a, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_013 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_013 + * @tc.desc Waiter does not spuriously notify on index which is subject to Store operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_013', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-store.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.store(i32a, 0, 0b1010); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_014 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_014 + * @tc.desc Waiter does not spuriously notify on index which is subject to xor operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_014', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/no-spurious-wakeup-on-xor.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + Atomics.xor(i32a, 0, 1); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_015 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_015 + * @tc.desc null timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_015', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/null-for-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_null_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 6) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(6); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_016 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_016 + * @tc.desc Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_016', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/object-for-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_object_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 6) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(6); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_017 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_017 + * @tc.desc Throws a TypeError if timeout arg can not be converted to number + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_017', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/poisoned-object-for-timeout-throws-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_poisoned_object_for_timeout_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'poisonedValueOf' || e.data == 'poisonedToPrimitive') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_018 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_018 + * @tc.desc Atomics.waitAsync returns a result object containing a property named "value" + * whose value is a promise that resolves to "ok" and async is true. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_018', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/returns-result-object-value-is-promise-resolves-to-ok.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)); + + let { async, value } = Atomics.waitAsync(i32a, 0, 0, 1000); + expect(async).assertEqual(true); + expect(value instanceof Promise).assertEqual(true); + expect(Object.getPrototypeOf(value)).assertEqual(Promise.prototype); + + value.then(outcome => { + expect(outcome).assertEqual("ok"); + done(); + }) + + Atomics.add(i32a, 0, 1); + Atomics.notify(i32a, 0, 1); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_019 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_019 + * @tc.desc Atomics.waitAsync returns a result object containing a promise that + * resolves to "timed-out" and async is true. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_019', 0, async function (done) { + // for test/built-ins/Atomics/waitAsync/returns-result-object-value-is-promise-resolves-to-timed-out.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)); + + let { async, value } = Atomics.waitAsync(i32a, 0, 0, 100); + value.then(outcome => { + expect(outcome).assertEqual("timed-out"); + done(); + }) + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_020 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_020 + * @tc.desc Throws a TypeError if index arg can not be converted to an Integer + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_020', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/symbol-for-index-throws-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_symbol_for_index_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'A TypeError' || e.data == 'B TypeError') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_021 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_021 + * @tc.desc Throws a TypeError if timeout arg can not be converted to an Number + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_021', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/symbol-for-timeout-throws-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_symbol_for_timeout_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'A TypeError' || e.data == 'B TypeError') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_022 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_022 + * @tc.desc Throws a TypeError if value arg is a Symbol + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_022', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/symbol-for-value-throws-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_symbol_for_value_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'A TypeError' || e.data == 'B TypeError') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_023 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_023 + * @tc.desc True timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_023', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/true-for-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_true_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(3); + expect(Atomics.notify(i32a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_024 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_024 + * @tc.desc True timeout arg should result in an +1 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_024', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/true-for-timeout.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + const valueOf = { + valueOf() { + return true; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } + }; + Promise.all([ + Atomics.waitAsync(i32a, 0, 0, true).value, + Atomics.waitAsync(i32a, 0, 0, valueOf).value, + Atomics.waitAsync(i32a, 0, 0, toPrimitive).value, + ]).then((results) => { + expect(results[0]).assertEqual("timed-out"); + expect(results[1]).assertEqual("timed-out"); + expect(results[2]).assertEqual("timed-out"); + done(); + }); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_025 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_025 + * @tc.desc Undefined timeout arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_025', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/undefined-for-timeout-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var result1 = 0; + var result2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_undefined_for_timeout01.js"); + let tt = new worker.Worker("entry/ets/workers/worker_wait_async_undefined_for_timeout02.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result1 = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + tt.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result2 = e.data; + } + } + + tt.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + flag = false; + tt.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + expect(Atomics.notify(i32a, 0, 2)).assertEqual(2); + while (result1 == 0 || result2 == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + flag = false; + tt.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(result1).assertEqual('A ok'); + expect(result2).assertEqual('B ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_026 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_026 + * @tc.desc Undefined timeout arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_026', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/undefined-for-timeout.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + const valueOf = { + valueOf() { + return undefined; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return undefined; + } + }; + + Promise.all([ + Atomics.waitAsync(i32a, 0, 0).value, + Atomics.waitAsync(i32a, 0, 0, undefined).value, + Atomics.waitAsync(i32a, 0, 0, valueOf).value, + Atomics.waitAsync(i32a, 0, 0, toPrimitive).value + ]).then((results) => { + expect(results[0]).assertEqual("ok"); + expect(results[1]).assertEqual("ok"); + expect(results[2]).assertEqual("ok"); + expect(results[3]).assertEqual("ok"); + done(); + }); + Atomics.notify(i32a, 0); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_027 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_027 + * @tc.desc Undefined index arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_027', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/undefined-index-defaults-to-zero-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var result1 = 0; + var result2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_undefined_index_defaults_to_zero01.js"); + let tt = new worker.Worker("entry/ets/workers/worker_wait_async_undefined_index_defaults_to_zero02.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result1 = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + tt.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result2 = e.data; + } + } + + tt.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + flag = false; + tt.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + expect(Atomics.notify(i32a, 0, 2)).assertEqual(2); + while (result1 == 0 || result2 == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + flag = false; + tt.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(result1).assertEqual('A ok'); + expect(result2).assertEqual('B ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_028 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_028 + * @tc.desc Test that Atomics.waitAsync returns the right result when it was awoken before a timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_028', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/was-woken-before-timeout.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var result = 0; + var lapse = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_was_woken_before_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else if (e.data == "ok") { + result = e.data; + } else { + lapse = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (!flag) { + await promiseCase(); + } + + expect(Atomics.notify(i32a, 0)).assertEqual(1); + while (result == 0 || lapse == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual('ok'); + expect(lapse < 10000).assertEqual(true); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_029 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_029 + * @tc.desc Returns "not-equal" when value arg does not match an index in the typedArray + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_029', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/value-not-equal-agent.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var res = 0; + var res2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_value_not_equal.js"); + + ss.onmessage = function (e) { + if (e.data == "not-equal") { + res = e.data; + } else { + res2 = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i32a); + while (res == 0 || res2 == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(res).assertEqual('not-equal'); + expect(res2).assertEqual(42); + expect(Atomics.notify(i32a, 0, 1)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_030 + * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_030 + * @tc.desc False timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_030', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/false-for-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_false_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 6) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(6); + expect(Atomics.notify(i64a, 0, 1)).assertEqual(0); + done(); + }) }) } \ No newline at end of file -- Gitee From bbc69fc74105d2e8ab7923cdf0751f7ee502700f Mon Sep 17 00:00:00 2001 From: wuwenlu Date: Sun, 7 Apr 2024 19:21:47 +0800 Subject: [PATCH 3/3] support Atomics.waitAsync for ECMA2024 patch 3 Signed-off-by: wuwenlu --- .../entry/src/main/ets/test/Atomics.test.js | 1427 ++++++++++++++++- 1 file changed, 1393 insertions(+), 34 deletions(-) diff --git a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js index be0ff91239..0808213fd1 100644 --- a/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js +++ b/commonlibrary/ets_utils/atomics_lib_standard/entry/src/main/ets/test/Atomics.test.js @@ -35,7 +35,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_NOTIFY_001 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_NOTIFY_001 + * @tc.name testCommonlibraryAtomicsNotify001 * @tc.desc returns a string which is either "ok", "not-equal", or "timed-out". * @tc.size MediumTest * @tc.type Function @@ -127,7 +127,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAIT_001 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAIT_001 + * @tc.name testCommonlibraryAtomicsWait001 * @tc.desc returns a string which is either "ok", "not-equal", or "timed-out". * @tc.size MediumTest * @tc.type Function @@ -177,7 +177,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_ADD_001 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_ADD_001 + * @tc.name testCommonlibraryAtomicsAdd001 * @tc.desc returns a string which is either "ok", "not-equal", or "timed-out". * @tc.size MediumTest * @tc.type Function @@ -230,7 +230,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_001 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_001 + * @tc.name testCommonlibraryAtomicsWaitAsync001 * @tc.desc False timeout arg should result in an +0 timeout * @tc.size MediumTest * @tc.type Function @@ -273,7 +273,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_002 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_002 + * @tc.name testCommonlibraryAtomicsWaitAsync002 * @tc.desc Test Atomics.waitAsync on arrays that allow atomic operations * @tc.size MediumTest * @tc.type Function @@ -314,7 +314,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_003 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_003 + * @tc.name testCommonlibraryAtomicsWaitAsync003 * @tc.desc Undefined timeout arg is coerced to zero * @tc.size MediumTest * @tc.type Function @@ -336,7 +336,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_004 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_004 + * @tc.name testCommonlibraryAtomicsWaitAsync004 * @tc.desc NaN timeout arg should result in an infinite timeout * @tc.size MediumTest * @tc.type Function @@ -383,7 +383,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_005 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_005 + * @tc.name testCommonlibraryAtomicsWaitAsync005 * @tc.desc Test that Atomics.waitAsync returns the right result when it timed out * and that the time to time out is reasonable. * @tc.size MediumTest @@ -431,7 +431,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_006 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_006 + * @tc.name testCommonlibraryAtomicsWaitAsync006 * @tc.desc Waiter does not spuriously notify on index which is subject to Add operation * @tc.size MediumTest * @tc.type Function @@ -484,7 +484,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_007 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_007 + * @tc.name testCommonlibraryAtomicsWaitAsync007 * @tc.desc Waiter does not spuriously notify on index which is subject to And operation * @tc.size MediumTest * @tc.type Function @@ -537,7 +537,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_008 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_008 + * @tc.name testCommonlibraryAtomicsWaitAsync008 * @tc.desc Waiter does not spuriously notify on index which is subject to compareExchange operation * @tc.size MediumTest * @tc.type Function @@ -590,7 +590,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_009 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_009 + * @tc.name testCommonlibraryAtomicsWaitAsync009 * @tc.desc Test that Atomics.waitAsync times out with a negative timeout * @tc.size MediumTest * @tc.type Function @@ -630,7 +630,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_010 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_010 + * @tc.name testCommonlibraryAtomicsWaitAsync010 * @tc.desc Waiter does not spuriously notify on index which is subject to exchange operation * @tc.size MediumTest * @tc.type Function @@ -683,7 +683,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_011 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_011 + * @tc.name testCommonlibraryAtomicsWaitAsync011 * @tc.desc Waiter does not spuriously notify on index which is subject to Or operation * @tc.size MediumTest * @tc.type Function @@ -736,7 +736,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_012 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_012 + * @tc.name testCommonlibraryAtomicsWaitAsync012 * @tc.desc Waiter does not spuriously notify on index which is subject to Sub operation * @tc.size MediumTest * @tc.type Function @@ -789,7 +789,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_013 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_013 + * @tc.name testCommonlibraryAtomicsWaitAsync013 * @tc.desc Waiter does not spuriously notify on index which is subject to Store operation * @tc.size MediumTest * @tc.type Function @@ -842,7 +842,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_014 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_014 + * @tc.name testCommonlibraryAtomicsWaitAsync014 * @tc.desc Waiter does not spuriously notify on index which is subject to xor operation * @tc.size MediumTest * @tc.type Function @@ -896,7 +896,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_015 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_015 + * @tc.name testCommonlibraryAtomicsWaitAsync015 * @tc.desc null timeout arg should result in an +0 timeout * @tc.size MediumTest * @tc.type Function @@ -940,7 +940,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_016 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_016 + * @tc.name testCommonlibraryAtomicsWaitAsync016 * @tc.desc Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 timeout * @tc.size MediumTest * @tc.type Function @@ -984,7 +984,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_017 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_017 + * @tc.name testCommonlibraryAtomicsWaitAsync017 * @tc.desc Throws a TypeError if timeout arg can not be converted to number * @tc.size MediumTest * @tc.type Function @@ -1028,7 +1028,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_018 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_018 + * @tc.name testCommonlibraryAtomicsWaitAsync018 * @tc.desc Atomics.waitAsync returns a result object containing a property named "value" * whose value is a promise that resolves to "ok" and async is true. * @tc.size MediumTest @@ -1055,7 +1055,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_019 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_019 + * @tc.name testCommonlibraryAtomicsWaitAsync019 * @tc.desc Atomics.waitAsync returns a result object containing a promise that * resolves to "timed-out" and async is true. * @tc.size MediumTest @@ -1075,7 +1075,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_020 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_020 + * @tc.name testCommonlibraryAtomicsWaitAsync020 * @tc.desc Throws a TypeError if index arg can not be converted to an Integer * @tc.size MediumTest * @tc.type Function @@ -1119,7 +1119,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_021 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_021 + * @tc.name testCommonlibraryAtomicsWaitAsync021 * @tc.desc Throws a TypeError if timeout arg can not be converted to an Number * @tc.size MediumTest * @tc.type Function @@ -1163,7 +1163,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_022 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_022 + * @tc.name testCommonlibraryAtomicsWaitAsync022 * @tc.desc Throws a TypeError if value arg is a Symbol * @tc.size MediumTest * @tc.type Function @@ -1207,7 +1207,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_023 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_023 + * @tc.name testCommonlibraryAtomicsWaitAsync023 * @tc.desc True timeout arg should result in an +0 timeout * @tc.size MediumTest * @tc.type Function @@ -1251,7 +1251,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_024 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_024 + * @tc.name testCommonlibraryAtomicsWaitAsync024 * @tc.desc True timeout arg should result in an +1 timeout * @tc.size MediumTest * @tc.type Function @@ -1285,7 +1285,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_025 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_025 + * @tc.name testCommonlibraryAtomicsWaitAsync025 * @tc.desc Undefined timeout arg is coerced to zero * @tc.size MediumTest * @tc.type Function @@ -1357,7 +1357,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_026 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_026 + * @tc.name testCommonlibraryAtomicsWaitAsync026 * @tc.desc Undefined timeout arg is coerced to zero * @tc.size MediumTest * @tc.type Function @@ -1396,7 +1396,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_027 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_027 + * @tc.name testCommonlibraryAtomicsWaitAsync027 * @tc.desc Undefined index arg is coerced to zero * @tc.size MediumTest * @tc.type Function @@ -1468,7 +1468,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_028 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_028 + * @tc.name testCommonlibraryAtomicsWaitAsync028 * @tc.desc Test that Atomics.waitAsync returns the right result when it was awoken before a timeout * @tc.size MediumTest * @tc.type Function @@ -1520,7 +1520,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_029 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_029 + * @tc.name testCommonlibraryAtomicsWaitAsync029 * @tc.desc Returns "not-equal" when value arg does not match an index in the typedArray * @tc.size MediumTest * @tc.type Function @@ -1566,7 +1566,7 @@ export default function WaitTest() { /** * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_030 - * @tc.name SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_030 + * @tc.name testCommonlibraryAtomicsWaitAsync030 * @tc.desc False timeout arg should result in an +0 timeout * @tc.size MediumTest * @tc.type Function @@ -1607,5 +1607,1364 @@ export default function WaitTest() { expect(Atomics.notify(i64a, 0, 1)).assertEqual(0); done(); }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_031 + * @tc.name testCommonlibraryAtomicsWaitAsync031 + * @tc.desc Get the correct WaiterList + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_031', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/waiterlist-block-indexedposition-wake.js + const i32a = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)); + + var flag1 = false; + var flag2 = false; + var result1 = 0; + var result2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake01.js"); + let tt = new worker.Worker("entry/ets/workers/worker_wait_async_waiterlist_block_indexed_position_wake02.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag1 = true; + } else { + result1 = e.data; + } + } + + ss.onexit = function () { + flag1 = true; + } + + tt.onmessage = function (e) { + if (e.data == "success") { + flag2 = true; + } else { + result2 = e.data; + } + } + + tt.onexit = function () { + flag2 = true; + } + + ss.postMessage(i32a); + while (!flag1) { + await promiseCase(); + } + + tt.postMessage(i32a); + while (!flag2) { + await promiseCase(); + } + flag1 = false; + flag2 = false; + expect(Atomics.notify(i32a, 1)).assertEqual(0); + expect(Atomics.notify(i32a, 3)).assertEqual(0); + expect(Atomics.notify(i32a, 2)).assertEqual(1); + expect(Atomics.notify(i32a, 0)).assertEqual(1); + while (result1 == 0 || result2 == 0 || !flag1 || !flag2) { + await promiseCase(); + } + + expect(result1).assertEqual('ok'); + expect(result2).assertEqual('ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_032 + * @tc.name testCommonlibraryAtomicsWaitAsync032 + * @tc.desc Test Atomics.waitAsync on arrays that allow atomic operations + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_032', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/good-views.js + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_good_views.js"); + + ss.onmessage = function (e) { + if (e.data == 'A timed-out' || e.data == 'B not-equal' + || e.data == 'C not-equal,not-equal,not-equal,not-equal,not-equal') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + ss.postMessage("start"); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(3); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_033 + * @tc.name testCommonlibraryAtomicsWaitAsync033 + * @tc.desc NaN timeout arg should result in an infinite timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_033', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/nan-for-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_nan_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == 'ok') { + res = e.data; + } + flag = true; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + + flag = false; + expect(Atomics.notify(i64a, 0)).assertEqual(1); + while (!flag) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(res).assertEqual('ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_034 + * @tc.name testCommonlibraryAtomicsWaitAsync034 + * @tc.desc Test that Atomics.waitAsync times out with a negative timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_034', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/negative-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_negative_timeout.js"); + + ss.onmessage = function (e) { + res = e.data; + flag = true; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_035 + * @tc.name testCommonlibraryAtomicsWaitAsync035 + * @tc.desc Waiter does not spuriously notify on index which is subject to Add operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_035', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-add.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.add(i64a, 0, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_036 + * @tc.name testCommonlibraryAtomicsWaitAsync036 + * @tc.desc Test that Atomics.waitAsync returns the right result when it timed out + * and that the time to time out is reasonable. + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_036', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-no-operation.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_no_operation.js"); + + ss.onmessage = function (e) { + if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_037 + * @tc.name testCommonlibraryAtomicsWaitAsync037 + * @tc.desc Waiter does not spuriously notify on index which is subject to compareExchange operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_037', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-compareExchange.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.compareExchange(i64a, 0, 0n, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_038 + * @tc.name testCommonlibraryAtomicsWaitAsync038 + * @tc.desc Waiter does not spuriously notify on index which is subject to exchange operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_038', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-exchange.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.exchange(i64a, 0, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_039 + * @tc.name testCommonlibraryAtomicsWaitAsync039 + * @tc.desc Waiter does not spuriously notify on index which is subject to And operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_039', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-and.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.and(i64a, 0, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_040 + * @tc.name testCommonlibraryAtomicsWaitAsync040 + * @tc.desc Waiter does not spuriously notify on index which is subject to Store operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_040', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-store.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.store(i64a, 0, 0b1010n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_041 + * @tc.name testCommonlibraryAtomicsWaitAsync041 + * @tc.desc Waiter does not spuriously notify on index which is subject to Or operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_041', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-or.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.or(i64a, 0, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_042 + * @tc.name testCommonlibraryAtomicsWaitAsync042 + * @tc.desc Waiter does not spuriously notify on index which is subject to xor operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_042', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-xor.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.xor(i64a, 0, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_043 + * @tc.name testCommonlibraryAtomicsWaitAsync043 + * @tc.desc Waiter does not spuriously notify on index which is subject to Sub operation + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_043', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/no-spurious-wakeup-on-sub.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var res = 0; + var lapse = 0; + var count = 0; + const ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_no_spurious_wakeup_on_add.js"); + + ss.onmessage = function (e) { + if (e.data == 'success') { + flag = true; + } else if (e.data == 'timed-out') { + res = e.data; + } else { + lapse = e.data; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + Atomics.sub(i64a, 0, 1n); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(lapse >= 200).assertEqual(true); + expect(res).assertEqual('timed-out'); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_044 + * @tc.name testCommonlibraryAtomicsWaitAsync044 + * @tc.desc null timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_044', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/null-for-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_null_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 6) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(6); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_045 + * @tc.name testCommonlibraryAtomicsWaitAsync045 + * @tc.desc Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_045', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/object-for-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_object_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 6) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(6); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_046 + * @tc.name testCommonlibraryAtomicsWaitAsync046 + * @tc.desc Throws a TypeError if index arg can not be converted to an Integer + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_046', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/symbol-for-index-throws-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_symbol_for_index_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'A TypeError' || e.data == 'B TypeError') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_047 + * @tc.name testCommonlibraryAtomicsWaitAsync047 + * @tc.desc Throws a TypeError if timeout arg can not be converted to number + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_047', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/poisoned-object-for-timeout-throws-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_poisoned_object_for_timeout_throws"); + + ss.onmessage = function (e) { + if (e.data == 'poisonedValueOf' || e.data == 'poisonedToPrimitive') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_048 + * @tc.name testCommonlibraryAtomicsWaitAsync048 + * @tc.desc Throws a TypeError if timeout arg can not be converted to an Number + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_048', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/symbol-for-timeout-throws-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_symbol_for_timeout_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'A TypeError' || e.data == 'B TypeError') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_049 + * @tc.name testCommonlibraryAtomicsWaitAsync049 + * @tc.desc Throws a TypeError if value arg is a Symbol + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_049', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/symbol-for-value-throws-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_symbol_for_value_throws.js"); + + ss.onmessage = function (e) { + if (e.data == 'A TypeError' || e.data == 'B TypeError') { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 2) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(2); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_050 + * @tc.name testCommonlibraryAtomicsWaitAsync050 + * @tc.desc True timeout arg should result in an +0 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_050', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var count = 0; + var result = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_true_for_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "timed-out") { + result++; + } + count++; + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (count != 3) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual(3); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_051 + * @tc.name testCommonlibraryAtomicsWaitAsync051 + * @tc.desc True timeout arg should result in an +1 timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_051', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/true-for-timeout.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + const valueOf = { + valueOf() { + return true; + } + }; + const toPrimitive = { + [Symbol.toPrimitive]() { + return true; + } + }; + Promise.all([ + Atomics.waitAsync(i64a, 0, 0n, true).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value + ]).then((results) => { + expect(results[0]).assertEqual("timed-out"); + expect(results[1]).assertEqual("timed-out"); + expect(results[2]).assertEqual("timed-out"); + done(); + }); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_052 + * @tc.name testCommonlibraryAtomicsWaitAsync052 + * @tc.desc Undefined timeout arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_052', 0, async function (done) { + // test262/data/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var result1 = 0; + var result2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_undefined_for_timeout01.js"); + let tt = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_undefined_for_timeout02.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result1 = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + tt.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result2 = e.data; + } + } + + tt.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + flag = false; + tt.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + expect(Atomics.notify(i64a, 0, 2)).assertEqual(2); + while (result1 == 0 || result2 == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + flag = false; + tt.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(result1).assertEqual('A ok'); + expect(result2).assertEqual('B ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_053 + * @tc.name testCommonlibraryAtomicsWaitAsync053 + * @tc.desc Undefined timeout arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_053', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/undefined-for-timeout.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + const valueOf = { + valueOf() { + return undefined; + } + }; + + const toPrimitive = { + [Symbol.toPrimitive]() { + return undefined; + } + }; + + Promise.all([ + Atomics.waitAsync(i64a, 0, 0n).value, + Atomics.waitAsync(i64a, 0, 0n, undefined).value, + Atomics.waitAsync(i64a, 0, 0n, valueOf).value, + Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value + ]).then((results) => { + expect(results[0]).assertEqual("ok"); + expect(results[1]).assertEqual("ok"); + expect(results[2]).assertEqual("ok"); + expect(results[3]).assertEqual("ok"); + done(); + }); + Atomics.notify(i64a, 0); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_054 + * @tc.name testCommonlibraryAtomicsWaitAsync054 + * @tc.desc Undefined index arg is coerced to zero + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_054', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/undefined-index-defaults-to-zero-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var result1 = 0; + var result2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero01.js"); + let tt = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_undefined_index_defaults_to_zero02.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result1 = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + tt.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else { + result2 = e.data; + } + } + + tt.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + flag = false; + tt.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + expect(Atomics.notify(i64a, 0, 2)).assertEqual(2); + while (result1 == 0 || result2 == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + flag = false; + tt.terminate(); + while (!flag) { + await promiseCase(); + } + + expect(result1).assertEqual('A ok'); + expect(result2).assertEqual('B ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_055 + * @tc.name testCommonlibraryAtomicsWaitAsync055 + * @tc.desc Returns "not-equal" when value arg does not match an index in the typedArray + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_055', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var res = 0; + var res2 = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_value_not_equal.js"); + + ss.onmessage = function (e) { + if (e.data == "not-equal") { + res = e.data; + } else { + res2 = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (res == 0 || res2 == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(res).assertEqual('not-equal'); + expect(res2 == 42n).assertEqual(true); + expect(Atomics.notify(i64a, 0, 1)).assertEqual(0); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_056 + * @tc.name testCommonlibraryAtomicsWaitAsync056 + * @tc.desc Get the correct WaiterList + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_056', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/waiterlist-block-indexedposition-wake.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)); + + var flag1 = false; + var flag2 = false; + var result1 = 0; + var result2 = 0; + let ss = new worker.Worker( + "entry/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake01.js"); + let tt = new worker.Worker( + "entry/ets/workers/worker_wait_async_bigint_waiterlist_block_indexed_position_wake02.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag1 = true; + } else { + result1 = e.data; + } + } + + ss.onexit = function () { + flag1 = true; + } + + tt.onmessage = function (e) { + if (e.data == "success") { + flag2 = true; + } else { + result2 = e.data; + } + } + + tt.onexit = function () { + flag2 = true; + } + + ss.postMessage(i64a); + while (!flag1) { + await promiseCase(); + } + + tt.postMessage(i64a); + while (!flag2) { + await promiseCase(); + } + flag1 = false; + flag2 = false; + expect(Atomics.notify(i64a, 1)).assertEqual(0); + expect(Atomics.notify(i64a, 3)).assertEqual(0); + expect(Atomics.notify(i64a, 2)).assertEqual(1); + expect(Atomics.notify(i64a, 0)).assertEqual(1); + while (result1 == 0 || result2 == 0 || !flag1 || !flag2) { + await promiseCase(); + } + + expect(result1).assertEqual('ok'); + expect(result2).assertEqual('ok'); + done(); + }) + + /** + * @tc.number SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_057 + * @tc.name testCommonlibraryAtomicsWaitAsync057 + * @tc.desc Test that Atomics.waitAsync returns the right result when it was awoken before a timeout + * @tc.size MediumTest + * @tc.type Function + * @tc.level Level 2 + */ + it('SUB_COMMONLIBRARY_ATOMICS_WAITASYNC_057', 0, async function (done) { + // for test262/data/test/built-ins/Atomics/waitAsync/bigint/was-woken-before-timeout.js + const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); + + var flag = false; + var result = 0; + var lapse = 0; + let ss = new worker.Worker("entry/ets/workers/worker_wait_async_bigint_was_woken_before_timeout.js"); + + ss.onmessage = function (e) { + if (e.data == "success") { + flag = true; + } else if (e.data == "ok") { + result = e.data; + } else { + lapse = e.data; + } + } + + ss.onexit = function () { + flag = true; + } + + ss.postMessage(i64a); + while (!flag) { + await promiseCase(); + } + + expect(Atomics.notify(i64a, 0)).assertEqual(1); + while (result == 0 || lapse == 0) { + await promiseCase(); + } + + flag = false; + ss.terminate() + while (!flag) { + await promiseCase(); + } + + expect(result).assertEqual('ok'); + expect(lapse < 10000).assertEqual(true); + expect(Atomics.notify(i64a, 0)).assertEqual(0); + done(); + }) }) -} \ No newline at end of file +} -- Gitee